Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

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-09-2004, 04:06 AM   PM User | #1
3D_Dog_Man
New Coder

 
Join Date: Feb 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
3D_Dog_Man is an unknown quantity at this point
Question NN4 Section of script not working

Hi Everyone,

I have a script that is designed to dynamically position page elements. It is working very well in IE6 and NN7. However I have tried the script in NN4 and it is not working at all. I have not yet had the opportunity to test this script on IE4! Please see the code below, the largely commented section toward the bottom of the script is where the NN4 commands are located. If you can help me with working out what is wrong with the way I have written this script I will be greatly appreciative.

<html>
<title> Simple Element Positioning Script </title>
<head>
<style type="text/css">
#car
{
position: absolute;
}
</style>
<script language="javascript" type="text/javascript">
// <!--
// Set an indicator variable to determine DOM supported by current browser.

var domIndicator = 0;

if(document.getElementById)
{
// IE5+ or NS6+ Browser detected.
domIndicator = 1;
}
else
if(document.all)
{
// IE4 Browser detected.
domIndicator = 2;
}
else
if(document.layers)
{
// NS4 Browser detected.
domIndicator = 3;
}

function posElem(elementID, xPos, yPos)
{
if(domIndicator == 1)
{
var element = document.getElementById(elementID);
element.style.left = xPos;
element.style.top = yPos;
}
else
if(domIndicator == 2)
{
var element = document.all.item(elementID);
element.style.posLeft = xPos;
element.style.posTop = yPos;
}
else
if(domIndicator == 3)
{
//When run in NN4 the following error message is produced regardless of
//which of the following techniques is used!

//JavaScript Error: file:/E|/Web Development/SimplePositioner.htm, line 52:
//**** document.elementID has no properties. ******

//document.layers[elementID].left = xPos;
//document.layers[elementID].top = yPos;

//document.elementID.left = xPos;
//document.elementID.top = yPos;

//var element = document.layers[elementID];
//element.left = xPos;
//element.top = yPos;
}
}

// -->
</script>
</head>
<body>
<img id="car" src="car.jpg">
<script type="text/javascript">
posElem('car', 100, 100);
</script>
</body>
</html>

Also if you can see anything wrong with the way the IE4 section is coded can you please point it out, as I am not in a position to check this section (I don't have IE4 - I guess not many people do). Thanks heaps for your assistance.

Regards

Davo

3D_Dog_Man is offline   Reply With Quote
Old 07-09-2004, 01:14 PM   PM User | #2
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Put the image inside the div tag and move the id there.

<div id="car"><img src="car.jpg" /></div>

and then use the original code:

document.layers[elementID].left = xPos;
document.layers[elementID].top = yPos;
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-09-2004, 05:14 PM   PM User | #3
MikeFoster
Regular Coder

 
Join Date: May 2004
Location: Alabama, USA
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
MikeFoster is an unknown quantity at this point
Another idea: Don't call posElem() in the body, call it in the onload event handler.

Quote:
Also if you can see anything wrong with the way the IE4 section...
element = document.all[elementID];

In NN4 if the positioned element is contained by another positioned element then you have to recurse thru document.layers[id].document.layers[id] etc. For example:

Code:
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;
  return e;
}
function xLayer(id,root) {
  var i,layer,found=null;
  if (!root) root=window;
  for(i=0; i<root.document.layers.length; i++) {
    layer=root.document.layers[i];
    if(layer.id==id) return layer;
    if(layer.document.layers.length) found=xLayer(id,layer);
    if(found) return found;
  }
  return null;
}
// taken from the X library, licensed LGPL
__________________
Cross-Browser.com, Home of the X Library
MikeFoster is offline   Reply With Quote
Old 07-09-2004, 05:18 PM   PM User | #4
MikeFoster
Regular Coder

 
Join Date: May 2004
Location: Alabama, USA
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
MikeFoster is an unknown quantity at this point
!!!

BTW, its almost sacrilegious to be discussing NN4 in the DOM forum ;-) LOL!
__________________
Cross-Browser.com, Home of the X Library
MikeFoster 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 08:12 AM.


Advertisement
Log in to turn off these ads.