Megan Garrison

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMegan Garrison
ToMe
Subjectx y re-positioning onResize
Date11 December 2004 01:04
Hi - I am So hoping you can help

I have a javascript menu that requires x y positioning. The code to call
it looks like this: 

<script>showPermPanel("MyMenu", 100, 120) </script> 
(e.g.<script>showPermPanel("Name", x, y) </script>) 

The problem is that I am using tables and I need the menu to be relative
to a certain table cell position and that cell position is different
depending on screen size/resolution. 

I am trying to correct this by using a bit of javascript to write the
x/y position relative to an image in the table cell, but the new x & y
positions are not being written with the correct offset (that I can
tell) & evidently IE has a problem with it giving 0,0, coordinates when
an image is nested inside a table. 

here is where I am so far: 

<div id='tdiv'><img src="images/shim.gif" 
width="1" height="1" alt=""></div> 
<script> 
onresize = function() { location.reload()} 
obj = document.getElementById('tdiv'); 
x = 120;                         /* x-coordinate of marker */ 
y = 170;                         /* y-coordinate of marker */ 
while (obj) { 
     x = x + obj.offsetLeft; 
     y = y + obj.offsetTop; 
     obj = obj.offsetParent; 
} 
document.write('<SCR' + 'IPT>' + 'showPermPanel(' + '"XP",'+ x + ',' + y
+')<\/SCR' + 'IPT>'); 

</script> 

I do not know javascript except to tinker with already written scripts
and I am having trouble tinkering with this one.  the original I was
trying to modify is: 

<br> 
<table border=1> 
  <tr> 
    <td> 
      Some Text 
    </td> 
    <td> 
      <div id='tdiv' style='background-color:#abcdef;'>Marker</div> 
    </td> 
  </tr> 
</table> 



<script> 
onresize = function() { location.reload()} 
obj = document.getElementById('tdiv'); 
x = 0;                         /* x-coordinate of marker */ 
y = 0;                         /* y-coordinate of marker */ 
while (obj) { 
     x = x + obj.offsetLeft; 
     y = y + obj.offsetTop; 
     obj = obj.offsetParent; 
} 
alert("Marker is at position " + x + "," + y); 
</script> 

any help would be appreciated 

thanks, Megan
FromMegan Garrison
ToMe
SubjectRe: x y re-positioning onResize
Date11 December 2004 02:15
Hi again - please disregard my previous email - turns out I just had the
script in the wrong place - it was inside the same table cell as the div
so of course it didn't cycle through all the parents, when I put it
outside all table tags at the bottom of the page just before the /body
it worked perfectly   - (ok one day well spent :P) 

Regards, megan
FromMe
ToMegan Garrison
SubjectRe: PS: x y re-positioning onResize
Date12 December 2004 15:37
Megan,

Firstly:
onresize = function() { location.reload()}
_very_ bad idea. this old bit of code was originally used to fix a bug in
Netscape 4 (may it rest in peace), but unfortunately it triggers a
different bug instead. the resize event is always fired as the page loads,
so the browser reloads the page thousands of times, getting lost in an
endless loop. Just remove that line of code. Netscape 4 is dead. and if it
isn't dead, it certainly should be. The rest of your code does not support
Netscape 4 anyway.

All other browsers don't need to reload when they resize. Simply calculate
the position when you show the menu instead of just when the page loads.

I am guessing that you are using IE on Mac. This is a well known bug, that
IE on Mac always returns the wrong position (typically 0,0) for the
position of a table cell. You need to put something inside the table cell
and get the position of that instead:
<td><a href="newPage.html" id="blah">New page</a></td>

obj = document.getElementById('blah');

The thing is that you seem to have done that. I don't have my mac to test
right now, but all the browsers I tested on windows seemed to get it right.
I cannot see any bug here.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromMe
ToMegan Garrison
SubjectRe: PS: x y re-positioning onResize
Date12 December 2004 15:39
Megan,

oops, I already replied - I should learn to read all emails before replying
:)

anyway, good to hear you got it working.


Tarquin
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.