!!blue Posted February 11, 2004 Posted February 11, 2004 As I'm sure many of you already know, IE has a problem with showing <abbr> tags correctly. If ya didn't know, now you know. The abbr tag allows you to have a word like HTML and when the viewer hovers over the word a "tooltip" shows up with what HTML means. The u can use CSS to underline all abbr's and show a "help" cursor when u roll over it. <abbr title="HyperText Markup Language">HTML</abbr> Don't even get me started on the whole acronym vs. abbr thing either. Mad!!! Anyways, I found a javascript code that'll check wether a browser is IE and change all the abbr in your html page and rewrite it so IE can render it properly. Here's the article about it Styling <abbr> in IE So my question is how can I have the JavaScript code in an external file and have the webpage it's linked in run it when the page loads. The code'll only work if it's in the head of the webpage but I don't want it there. >function styleAbbr() { var oldBodyText, newBodyText, reg if (isIE) { oldBodyText = document.body.innerHTML; reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g; newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>'); document.body.innerHTML = newBodyText; } } window.onload = function(){ styleAbbr() }; isIE = (document.all) ? true:false; I tried adding the function to the body onload tag like so: <body onload="preload('images/window.gif','images/red.png'); styleAbbr();"> but that didn't work either. I want to have the above function in an external js file and run when the page is loaded. any ideas? thanks, !!blue Quote
btrfld Posted February 11, 2004 Posted February 11, 2004 What if you took the code out of the function, and had it 'loose' in the .js file. Would it then be evaluated when the file is loaded? Quote
!!blue Posted February 11, 2004 Author Posted February 11, 2004 nope, that didn't work, now it tells me (the javascript console anyway) that -- Error: isIE is not defined. so no good Quote
btrfld Posted February 11, 2004 Posted February 11, 2004 At least the error is telling you that the script is being executed. Try putting isIE = (document.all) ? true:false; at the top of the linked file. Or simply change the if() statement to read if(document.all) Quote
!!blue Posted February 11, 2004 Author Posted February 11, 2004 no more error but isn't doing what it's supposed to be doing errr.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.