/    Sign up×
Community /Pin to ProfileBookmark

Netscape & Javascript

Hello,

I have this javascript that let’s the user see the latitude and longitude when they move the mouse over an image. The problem is that this only works in explorer and not netscape or mozilla. I was wondering if anyone could give me any help on getting this to work on netscape and or firefox too. You can see it in action here:

[url]http://bsrsi.msu.edu/cgi-bin/gz/e0010541219002[/url]

And this is the javascript:

[CODE]function SubmitForm() {
document.forms[1].elements[“imagex”].value = nowX;
document.forms[1].elements[“imagey”].value = nowY;
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) {
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;
with (document.forms[0]) {
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];
document.onmousemove = DispCoords;
} [/CODE]

And here is where the html calls upon the javascript:

[CODE]if($got_coords) {
if ($width < 300) { $layerorigin = 200; }
elsif ($width < 550) { $layerorigin = 100; }
else { $layerorigin = 10; }
if($clientware =~ m/msie/) { $layerorigin -= 15; }
$coo_string = “${ULX2_geo},${ULY2_geo},${LRX2_geo},${LRY2_geo},${ULX2_utm},${ULY2_utm},${LRX2_utm},${LRY2_utm}”;
print <<“__INSERTIMAGE__”;
<DIV ID=”ImgLayer” STYLE=”left:${layerorigin}; top:${imagetop};”>
<A HREF=”javascript:SubmitForm();” onMouseOver=”DoIt(${coo_string});”>
<IMG ALT=”” WIDTH=$width HEIGHT=$height src=”/tmssb/${imgnum}.jpg” BORDER=0></A>
</DIV>

__INSERTIMAGE__
}
else {
print “<P><input WIDTH=$width HEIGHT=$height type=image name=image src=”/tmssb/${imgnum}.jpg” BORDER=0><BR>n”;
}
} [/CODE]

ANY help would be appreciated! Also any websites that you can point me to that can help me would be great. I tried looking this up…but I don’t have much experience with java, so I am clueless as to where to start. THANK YOU.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterApr 29.2005 — [color=royalblue]document.onmousemove = DispCoords;[/color]

Isn't enough to capture an event in most browsers...

Replace that with:
<i>
</i>document.onmousemove = DispCoords;
if(window.captureEvents)
window.captureEvents(Event.ONMOUSEMOVE)
×

Success!

Help @nguye103 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...