Hi all,
I’m pretty new to this coding lark but managed to wangle some code together (copy & paste for the win!) however, I’ve discovered something strange I was hoping some JS guru could help with?
If you visit my webpage http://badgerfruit.homeip.net/test.php you will see two links “Home Page” and “Album”.
Hovering the mouse over these links should draw up a 300x300px “preview” of the page you’re hovering over.
You will notice that the first time you hover over a link, you get a blank, grey preview box. Hover over another link and the ORIGINALLY hovered preview will be displayed.
I guess this is because the <span> tag I have populated updates when it should but the code is displaying what was in there BEFORE it loads the new content into it.
I apologise as it’s a bit difficult to explain but if you follow the URL above, you will be able to see for yourself.
I have tried
- adding a delay in AFTER the “showHint” function is run, this did not work, instead, it just delayed the rest of the functions called onmouseover
- adding multiple <span>s but the behaviour repeats (as in, first mouseover shows nothing but subsequent ones do)
The code was swiped from w3schools’ AJAX tutorial and the popup “preview” was found at Web Development, JavaScripts for Download
The code for test.php is shown below
<html>
<head>
<LINK REL=stylesheet HREF="/style.css" TYPE="text/css">
<script language=javascript>
<!--
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url=str;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}
//-->
</script>
</head>
<body>
<script type="text/javascript" src="wz_tooltip.js"></script>
<span id="txtHint"></span>
<a href="index.php" onmouseover="showHint('index.php'); TagToTip('txtHint',FADEIN,000,DELAY,000,WIDTH,300,HEIGHT,300,BORDERCOLOR,'#FF0000',TITLE,'Page preview') " onmouseout="UnTip()">Home page </a><br>
<a href="/album/index.php" onmouseover="showHint('/album/index.php'); TagToTip('txtHint',FADEIN,000,DELAY,000,WIDTH,300,HEIGHT,300,BORDERCOLOR,'#FF0000',TITLE,'Page preview'); return; " onmouseout="UnTip()">Photo Album</a>
</body>
</html>
If anyone can help I will be eternally grateful!