Quotes in IE/Win

I made this 11 years 37 weeks ago

The following quotes are marked up with <q> tags. IE/Win doesn't automatically insert quote marks (unlike Opera, Firefox and others).

DOM scripting is used to add these for IE/Win users. To make sure other browsers don't run the script, and end up with duplicate quotes, the script is called from a conditional comment.

Example

Without WTI support it would have been impossible for us to fund an expensive visit to Tokyo, said Ms Rushton.

Our visit enabled us to move forward with our exporting plans, providing an excellent opportunity for us to meet potential clients face-to-face, and creating an opportunity for us to talk them through our product range.

The following paragraph has quotes hard-coded for comparison (using &ldquo; and &rdquo;).

“Without WTI support it would have been impossible for us to fund an expensive visit to Tokyo,” said Ms Rushton.

“Our visit enabled us to move forward with our exporting plans, providing an excellent opportunity for us to meet potential clients face-to-face, and creating an opportunity for us to talk them through our product range.”

Code

Here is my quotes.js script file. I'm sure you could write it better. Anyway, it's just an example.


/*enhance quotes*/ 

//define quotes 
var quote = new Object(); 
quote.quote_open = "&lsquo;"; 
quote.quote_close = "&rsquo;"; 
quote.double_quote_open = "&ldquo;"; 
quote.double_quote_close = "&rdquo;"; 

//add opening and closing quote marks to <q> elements 
function addQuotes() 
{ 
   if (document.getElementById) 
   { 
      var _quotes = document.getElementsByTagName('q'); 
      for (x=0; x<_quotes.length; x++) 
      { 
         var _quote = _quotes[x]; 
         _quote.innerHTML = quote.double_quote_open + _quote.innerHTML + quote.double_quote_close; 
      } 
   } 
} 

if (window.addEventListener) 
{ 
   window.addEventListener('load', addQuotes, false) 
} 
else if (window.attachEvent) 
{ 
   window.attachEvent('onload', addQuotes) 
}
	

You can then call it from your HTML page like so :-

	
<!--[if IE]>
<script type="text/javascript" src="scripts/quotes.js"></script>
<![endif]-->