Jump to content

IE probs


IDK

Recommended Posts

Why does IE say it can use document.getElementById when it can't?How can I fix this?

  if(document.all) {    var titletext=document.all["titletext"];  }  else if(document.getElementById)   {    var titletext=document.getElementById("titletext");  }

this doesn't work!!How? Why? When??Please help me, I'm a programmer but hate messy unexplainable problems...

Link to comment
Share on other sites

It works with Firefox...When I try to modify the object it doesn't work, but if I put an alert in the middle it executes.I just want the following to work under IE and FFIt seams like IE doesn't like me :)

function updatetitle(){  if(document.all) {    var titletext=document.all["titletext"];    var theiframe=document.all["theiframe"];    var leftline=document.all["leftline"];    var rightline=document.all["rightline"];  }  else if(document.getElementById)   {    var titletext=document.getElementById("titletext");    var theiframe=document.getElementById("theiframe");    var leftline=document.getElementById("leftline");    var rightline=document.getElementById("rightline");  }  titletext.innerHTML=theiframe.contentDocument.title;  var titlelength=theiframe.contentDocument.title.length;  leftline.style.width= 350 - titlelength * 5;  rightline.style.width= 310 - titlelength * 5;}

Then if it can't be done with IE, I would want to put some other code there instead to make it a little nicer, but it wont allow that either becouse both of the if statements is true in IE.

Link to comment
Share on other sites

hmm... well I don't know if this will work, but it would be worth a try. Make the first possible condition be document.getElementById, seeing as that works in both FF and IE and should be the first choice of action, not document.all. Perhaps the document.all is being called and not working as it should since it's depricated. it might also be worth trying:

function updatetitle(){ var titletext=document.getElementById("titletext"); var theiframe=document.getElementById("theiframe"); var leftline=document.getElementById("leftline"); var rightline=document.getElementById("rightline"); titletext.innerHTML=theiframe.contentDocument.title; var titlelength=theiframe.contentDocument.title.length; leftline.style.width= 350 - titlelength * 5; rightline.style.width= 310 - titlelength * 5;}

Link to comment
Share on other sites

From what I see it's working just like you should expect.

if(document.all) {  var titletext=document.all["titletext"]; } else if(document.getElementById) {  var titletext=document.getElementById("titletext"); }
Since IE tests "true" at 'if(document.all)' it never checks the 'else if'.You could invert your test.Thanks,
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...