Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnMouseOver with netscape and firefox

Status
Not open for further replies.

nguye103

Technical User
Apr 21, 2005
7
US
Hi,
I am not very experienced with javascript at all, but i need to modify a website that contains javascript. I am using a program that uses the mouseover function to show the latitude and longitude of an area when the user scrolls over a picture of a map. This program works fine in internet explorer, but does not work with netscape7 or firefox. I have no idea how to go about making it work for these browsers. Here is the script to the mouseover. Any help would be appreciated! THANK YOU!

function Is() {
var agent = navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
this.ns2 = (this.ns && (this.major == 2));
this.ns3 = (this.ns && (this.major == 3));
this.ns4b = (this.ns && (this.minor < 4.04));
this.ns4 = (this.ns && (this.major >= 4));
this.ie = (agent.indexOf("msie")!= -1);
this.ie3 = (this.ie && (this.major == 2));
this.ie4 = (this.ie && (this.major >= 4));
this.op3 = (agent.indexOf("opera")!= -1);
this.win = (agent.indexOf("win")!=-1);
this.mac = (agent.indexOf("mac")!=-1);
this.unix = (agent.indexOf("x11")!=-1);
}
var is = new Is();
if(is.ns4) {
doc = "document";
sty = "";
htm = ".document"
} else if(is.ie4) {
doc = "document.all";
sty = ".style";
htm = ""
}

redVal = 0;
grnVal = 0;
bluVal = 0;
zoomVal = 9;
sizeVal = 9;

function SubmitForm() {
//if (redVal > 0) { redVal++; if (redVal == 6) { redVal++; }}
//else { redVal = document.forms[1].elements["lastred"].value; }
//if (grnVal > 0) { grnVal++; if (grnVal == 6) { grnVal++; }}
//else { grnVal = document.forms[1].elements["lastgrn"].value; }
//if (bluVal > 0) { bluVal++; if (bluVal == 6) { bluVal++; }}
//else { bluVal = document.forms[1].elements["lastblu"].value; }
//if (zoomVal == 9) { zoomVal = document.forms[1].elements["lastlevel"].value; }
//if (sizeVal == 9) { sizeVal = document.forms[1].elements["lastsize"].value; }
//document.forms[1].elements["imagex"].value = xVal;
//document.forms[1].elements["imagey"].value = yVal;
document.forms[1].elements["imagex"].value = nowX;
document.forms[1].elements["imagey"].value = nowY;
//document.forms[1].elements["red"].value = redVal;
//document.forms[1].elements["grn"].value = grnVal;
//document.forms[1].elements["blu"].value = bluVal;
//document.forms[1].elements["level"].value = zoomVal;
//document.forms[1].elements["size"].value = sizeVal;
document.forms[1].submit();
}
function DoHocusPocus() {
deltaXgeo = Math.abs(lowerRightXgeo - upperLeftXgeo);
deltaYgeo = Math.abs(lowerRightYgeo - upperLeftYgeo);
pctX = nowX / ImgX;
pctY = nowY / ImgY;
offsetXgeo = deltaXgeo * pctX;
offsetYgeo = deltaYgeo * pctY;
NewXgeo = upperLeftXgeo + offsetXgeo;
NewYgeo = upperLeftYgeo - offsetYgeo;
NewXshortgeo = ( Math.round( NewXgeo * 1000000)) / 1000000;
NewYshortgeo = ( Math.round( NewYgeo * 1000000)) / 1000000;
document.forms[0].elements[1].value = NewXshortgeo;
document.forms[0].elements[0].value = NewYshortgeo;

deltaXutm = Math.abs(lowerRightXutm - upperLeftXutm);
deltaYutm = Math.abs(lowerRightYutm - upperLeftYutm);
offsetXutm = deltaXutm * pctX;
offsetYutm = deltaYutm * pctY;
NewXutm = upperLeftXutm + offsetXutm;
NewYutm = upperLeftYutm - offsetYutm;
NewXshortutm = Math.round( NewXutm );
NewYshortutm = Math.round( NewYutm );
document.forms[0].elements[3].value = NewXshortutm;
document.forms[0].elements[2].value = NewYshortutm;
}

function DispCoords(eventType) {
if(is.ns4) {
ImgLayer = document.layers.ImgLayer;
xVal = eventType.layerX;
yVal = eventType.layerY;
ImgX = ImgLayer.clip.width;
ImgY = ImgLayer.clip.height;
xClick = eventType.layerX;
yClick = eventType.layerY;
} else {
xVal = parseInt(window.event.x);
yVal = parseInt(window.event.y);
layerArray = document.all.item("ImgLayer");
imgLayer = document.all.item("ImgLayer").style;
ImgX = document.images[0].width;
ImgY = document.images[0].height;
//xClick = evtObj.layerX;
//yClick = evtObj.layerY;
}

with (document.forms[0]) {
if(is.ns4) {
if (( eventType.pageX > ImgLayer.pageX) && (eventType.pageY > ImgLayer.pageY)) {
if (xVal <= ImgX && yVal <= ImgY) {
nowX = xVal;
nowY = yVal;
DoHocusPocus();
}
}
} else if(is.ie4 ¦¦ is.ie5) {
if ( xVal > parseInt(imgLayer.left) && yVal > parseInt(imgLayer.top) ) {
if ( xVal <= (parseInt(imgLayer.left) + ImgX) && yVal <= (parseInt(imgLayer.top) + ImgY)) {
nowX = xVal - parseInt(imgLayer.left);
nowY = yVal - parseInt(imgLayer.top);
DoHocusPocus();
}
}
}
}
}

function DoIt() {
upperLeftXgeo = arguments[0];
upperLeftYgeo = arguments[1];
lowerRightXgeo = arguments[2];
lowerRightYgeo = arguments[3];
upperLeftXutm = arguments[4];
upperLeftYutm = arguments[5];
lowerRightXutm = arguments[6];
lowerRightYutm = arguments[7];

if(is.ns4) {
window.captureEvents(Event.MOUSEMOVE);
window.onMouseMove = DispCoords;
}
else if((is.ie4) ¦¦ (is.ie5)) {
document.onmousemove = DispCoords;
}
}
 
Firstly, checking the user-agent string to work out browser compliance is an inaccurate way.

Second, check your case: it's onMouseOver (lower-case o to begin with).

In Firefox, click on Tools >> JavaScript Console. This'll show you any errors and help debug your script.

You may want your onMouseOver script to start with an alert, simply to check it's being called.

<marc>
 
I tried doing what you said with Firefox, but there were no errors or anything. I think this is because the website goes to a different page if the browser is not one of the ones indicated in the script. Here is where the application is being used:


The guy that made this script quit a couple of years ago, so I am my own...and I have no clue what to do...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top