Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-04-2003, 01:39 PM   PM User | #1
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
Question getelementbyid

Hi everybody,

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 
= 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.
jefkaone is offline   Reply With Quote
Old 07-10-2003, 03:22 PM   PM User | #2
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
hi, someone got a idea? , ++,jefkaOne.
jefkaone is offline   Reply With Quote
Old 07-10-2003, 03:42 PM   PM User | #3
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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...
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 07-10-2003, 04:13 PM   PM User | #4
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
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.
jefkaone is offline   Reply With Quote
Old 07-10-2003, 04:30 PM   PM User | #5
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 07-10-2003, 04:39 PM   PM User | #6
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
Mozilla has very helpful error reporting. What is it telling you?

Menu: Tools >> Web Developement >> JavaScript console
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 07-10-2003, 04:50 PM   PM User | #7
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
hi beetle,
thx for the tricks, this console returns me that "positionLayer is not defined"?!, who can i defined it before onLoad? thx.

Kor, like with the windows.init, it doesn't work , amlways the same, with IE ok but not with MOZILLA.

Last edited by jefkaone; 07-10-2003 at 04:53 PM..
jefkaone is offline   Reply With Quote
Old 07-10-2003, 04:56 PM   PM User | #8
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
is it

onload="setLyr(positionLayer,'LayerWhoNeedToBePositionned)"

exactly what u have written?

'cose here might be a problem
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 07-10-2003, 05:24 PM   PM User | #9
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
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">&nbsp;</div> , mozilla don't understand.
jefkaone is offline   Reply With Quote
Old 07-10-2003, 06:29 PM   PM User | #10
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
Ah, setLyr expects an object reference as the first parameter which means you should call it like this (when you can't use "this"):

onload="setLyr(document.GetElementById('positionLayer'),'LayerWhoNeedToBePositionned)"


The reason it works in IE is because they pollute the global object space with everything that's given an "id" value.
__________________
Check out the Forum Search. It's the short path to getting great results from this forum.
Roy Sinclair is offline   Reply With Quote
Old 07-10-2003, 06:36 PM   PM User | #11
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
Quote:
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?
jefkaone is offline   Reply With Quote
Old 07-10-2003, 08:08 PM   PM User | #12
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
document.getElementById() doesn't work for IE4 or NS4.x.

jkd wrote a handy function a while back to abstract this process
Code:
function getNode( id )
{
    return ( document.layers ) ? document.layers[id] : ( document.getElementById || document.all )( id );
}
so, your code would change like this
Code:
onload="setLyr(getNode('positionLayer'),'LayerWhoNeedToBePositionned')"
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 07-11-2003, 09:34 AM   PM User | #13
jefkaone
New to the CF scene

 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
jefkaone is an unknown quantity at this point
Hi , for the trick of getElementById, mozilla show me thiserror:

Erreur : uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: http://localhost/hhwomen/menu/chanteuses.php3 :: getNode :: line 49" data: no]

what does it mean? thx, jefkaOne.
jefkaone is offline   Reply With Quote
Old 07-11-2003, 03:29 PM   PM User | #14
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
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.
Roy Sinclair is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:02 PM.


Advertisement
Log in to turn off these ads.