Jump to content

Recommended Posts

Posted

 

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

Posted

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?

Posted

nope, that didn't work, now it tells me (the javascript console anyway) that --

Error: isIE is not defined. :)

 

so no good :)

Posted

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...