IDK Posted October 22, 2005 Share Posted October 22, 2005 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 More sharing options...
actionsketch Posted October 23, 2005 Share Posted October 23, 2005 isolate just the individual statements and make sure its the getElementById line that is screwing it up. Link to comment Share on other sites More sharing options...
IDK Posted October 23, 2005 Author Share Posted October 23, 2005 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 More sharing options...
actionsketch Posted October 23, 2005 Share Posted October 23, 2005 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 More sharing options...
Jonas Posted October 23, 2005 Share Posted October 23, 2005 It seams like IE doesn't like me Hey, as long as it's mutual... Link to comment Share on other sites More sharing options...
hacknsack Posted October 24, 2005 Share Posted October 24, 2005 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now