For my first post, i've got a problem with a script wich have to repositioned a layer in by page trought a div balise, all is working great, except with mozilla, my script is this one:
PHP Code:
<SCRIPT>
function setLyr(obj,lyr)
{
var newX = findPosX(obj);
var newY = findPosY(obj);
if (lyr == 'testP') newY -= 50;
var x = new getObj(lyr);
x.style.top = newY + 'px';
x.style.left = newX + 'px';
}
function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function findPosY(obj)
{
var curtop = 0;
var printstring = '';
if (obj.offsetParent)
{
while (obj.offsetParent)
{
printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
window.status = printstring;
return curtop;
}
function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
if (document.layers[name])
{
this.obj = document.layers[name];
this.style = document.layers[name];
}
else
{
this.obj = document.layers.testP.layers[name];
this.style = document.layers.testP.layers[name];
}
}
}
</SCRIPT>
then, i've got in my page the div element wich is the repair of the layer <div id="positionLayer"> </div> and in body, i write : onload="setLyr(positionLayer,'LayerWhoNeedToBePositionned)", all ok with IE but not Mozilla, what i need more to make it works with mozilla?
thancs for all, ++, jefkaOne.
maybe you should use for mozilla <layer>and probably <ilayer> instead of <div>... I don't know... but I remember that I have to do that for a similar script in NS4...
hi , thx for your help,
i tryed but it doesn't work like this. the thing witch is warning me is that if if made a link with the JSfunction, it works on IE like on MOZILLa, but when i use the JSfunction with onload in the body, niet, it doesn't work on MOZILLA . :S
++,jefkaone.
Try than using onload within the function, write somewere inside the script
window.onload = init;
function init() {
setLyr(....,....);
}
and remove onload from the body. It seems the same for me, but maybe Mozilla does not to call a function with arguments directly from onload... I don't have/use Mozilla, so I can not taste, sorry.
if i made for example a link like this:
<a href="#" onMouseOver="setLyr(this,'layeraffiche');">Position</a>
the layer is positionned on the link ("this"), but if i write the name of a layer in order to named and identified the position: setLyr(positionLayer,'layeraffiche') //positionLayer is :<div id="positionLayer"> </div> , mozilla don't understand.
Originally posted by Roy Sinclair
The reason it works in IE is because they pollute the global object space with everything that's given an "id" value. [/B]
:S so baddddddd lol, thx for all, it's now working , ultimate question, this solution works with all navigators?
It means you've somehow hit a bug in the browser which causes the browser to crash. Try adding an alert into the code and moving it around until you find the spot where the code causes the browser to crash, let us know what that code is and we'll try to get you some alternative code that won't crash the browser.
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.