PDA

View Full Version : سوال: کد زیر چرا در مرورگرهای غیر اینترنت اکسپلورر کار نمیکنه؟



m_feyz
سه شنبه 12 مرداد 1389, 16:20 عصر
با سلام. کد زیر برای نمایش پنجره کوچک هنگام قرار کرفتن ماوس روی آن است ولی در فایرفاکس و سایر مرورگرها به غیر از اینترنت اکسپلورر کار نمیکنه. علتش چیه؟

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function setupDescriptions() {
var x = navigator.appVersion;
y = x.substring(0,4);
if (y>=4) setVariables();
}
var x,y,a,b;
function setVariables(){
if (navigator.appName == "Netscape") {
h=".left=";
v=".top=";
dS="document.";
sD="";
}
else
{
h=".pixelLeft=";
v=".pixelTop=";
dS="";
sD=".style";
}
}
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function popLayer(a){
desc = "<table cellpadding=3 border=1 bgcolor=F7F7F7><td>";
if (a==1) desc += "JavaScript Source Code 3000 Home Page!";
if (a==2) desc += "Updates on all the latest scripts added to the site!";
if (a==3) desc += "Browser our Table of Contents page!";
if (a==4) desc += "Get JavaScript assistance in our JS forum!";
if (a==5) desc += "Get the answers to our commonly asked JS questions!";
desc += "</td></table>";
if(isNav) {
document.object1.document.write(desc);
document.object1.document.close();
document.object1.left=x+25;
document.object1.top=y;
}
else {
object1.innerHTML=desc;
eval(dS+"object1"+sD+h+(x+25));
eval(dS+"object1"+sD+v+y);
}
}
function hideLayer(a){
if(isNav) {
eval(document.object1.top=a);
}
else object1.innerHTML="";
}
function handlerMM(e){
x = (isNav) ? e.pageX : event.clientX;
y = ( (isNav) ? e.pageY : event.clientY )+document.body.scrollTop;
}
if (isNav){
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = handlerMM;
// End -->
</script>
</head>
<BODY OnLoad="setupDescriptions()">
<div id="object1" style="position:absolute; visibility:show; left:25px; top:-50px; z-index:2">layer hidden off the screen</div>
<a href="http://javascriptsource.com" onMouseOver="popLayer(1)" onMouseOut="hideLayer(-50)">Home Page</a>
<p>
</body>
</html>

exlord
چهارشنبه 13 مرداد 1389, 14:55 عصر
FireFox Error Console

Warning: Use of captureEvents() is deprecated. To upgrade your code, use the DOM 2 addEventListener() method. For more help http://developer.mozilla.org/en/docs/DOM:element.addEventListener


Warning: Error in parsing value for 'visibility'. Declaration dropped.


Error: document.object1 is undefined


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all ? true : false
// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0
function show() {
// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
}
function hide() {
document.onmousemove = null;
document.getElementById('object1').style.display = "none";
}
// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0) { tempX = 0 }
if (tempY < 0) { tempY = 0 }
// show the position values in the form named Show
// in the text fields named MouseX and MouseY
document.getElementById('object1').style.top = tempY + 15 + 'px';
document.getElementById('object1').style.left = tempX + 20 + 'px';
document.getElementById('object1').style.display = "block";
return true
}

<div id="object1" style="position: absolute;top:0px;left:0px; display:none; z-index: 100">