/    Sign up×
Community /Pin to ProfileBookmark

Position on page

Hi guys,

I have the following code on my page :

[CODE]
<script language=”javascript” type=”text/javascript”>
<!– Begin
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSECLICK)
document.onclick = getMouseXY;
var tempX = 0;
var tempY = 0;
var continue1 = true;
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;
}
tempX = tempX-130;
if (tempX <0){continue1 = false;}
if (tempX > 1000){continue1 = false;}
tempY = tempY-120;
if (tempY <0){continue1 = false;}
if (tempY > 1000){continue1 = false;}

if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}

if(continue1 != false){
window.location=”./whichpixel.php?co=”+tempX+”,”+tempY;
}
}
// End –>
</script>
[/CODE]

The script gets the x,y of the mouse and redirects to whichpixel.php onclick. the <0 >1000 is just because thats how big my image is (1000×1000).

The script works great, but when the user scrolls, the script only works for the current display, not the page as a whole. Any ideas ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsMay 22.2006 — [CODE]
function zxcMse(event){
if(!event) var event=window.event;
if (event.clientX){ return [event.clientX+zxcDocS()[0],event.clientY+zxcDocS()[1]]; }
else { return[event.pageX,zxcMseY=event.pageY]; }
}

function zxcDocS(){
var zxcsx,zxcsy;
if (!document.body.scrollTop){ zxcsx=document.documentElement.scrollLeft; zxcsy=document.documentElement.scrollTop; }
else { zxcsx=document.body.scrollLeft; zxcsy=document.body.scrollTop; }
return [zxcsx,zxcsy];
}
[/CODE]
Copy linkTweet thisAlerts:
@chickenlandauthorMay 22.2006 — Sorry, but could you give me an example ? My Javascript knowledge has big gaps in it ?
Copy linkTweet thisAlerts:
@chickenlandauthorMay 23.2006 — Right, my code now stands at :

[CODE]
<script>
function zxcMse(event){
if(!event) var event=window.event;
if (event.clientX){ return [event.clientX+zxcDocS()[0],event.clientY+zxcDocS()[1]]; }
else { return[event.pageX,zxcMseY=event.pageY]; }
}

function zxcDocS(){
var zxcsx,zxcsy;
if (!document.body.scrollTop){ zxcsx=document.documentElement.scrollLeft; zxcsy=document.documentElement.scrollTop; }
else { zxcsx=document.body.scrollLeft; zxcsy=document.body.scrollTop; }
return [zxcsx,zxcsy];
}

function alertit(coords){
var tempX = coords[0];
var tempY = coords[1];
var continue1 = true;

tempX = tempX-130;
if (tempX <0){continue1 = false;}
if (tempX > 1001){continue1 = false;}
tempY = tempY-120;
if (tempY <0){continue1 = false;}
if (tempY > 1001){continue1 = false;}

if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}

if(continue1 != false){
//alert(tempX+', '+tempY);
window.location="./whichpixel.php?co="+tempX+","+tempY;
}
}
</script>
[/CODE]


and is called : <a href="#" onclick="var coords = zxcMse(); alertit(coords);">

<img src="./images/grid.gif" border="0" />

</a>

All works great... in Internet Explorer, but FF moans that "event has no properties", and Safari sits and waves a white flag at me. Any ideas ?
Copy linkTweet thisAlerts:
@vwphillipsMay 23.2006 — cant see the complete script, post a link

sure that you have the id assigned and not just a name
×

Success!

Help @chickenland 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.28,
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,
)...