Is there any way to format Javascript and not get IE8 errors?

The problem I had was that I simplified the following script to make it easier to read and debug.

The script worked without errors in Chrome, Opera, Safari and Firefox even with FireBug.

Unfortunately IE8 through a wobbler because I had the Internet options “Display a notifcation about every script error” checked. The IE8 error was “Unterminated string constant”.

Here is the script:



<a 
 href='http://localhost/index-java-error.php' 
 onclick=
 "
  window.open
  (
    '/function_sendmail.php?sendurl=www.example.com/', 
    '_blank',
   '
    width=300,	
    height=420,
    toolbar=no,
    menubar=no,
    scrollbars=no,
    resizable=no,
    location=no,
    directories=no,
    status=no,
    top=150,
    left=150
   ', 0
  );
"
>
<img 
  src='button_sendpage.gif' 
  style='margin-left:5px;border:0' 
  alt='Send This Page to Friend' 
/>
</a>


I eventually found the error which was to remove every single linefeed from the “width height, toolbar, etc”.

Is there a way to format Javascript and not produce IE8 errors?

.

Your best option is to move the JavaScript into its own file separate from the HTML. Then the JavaScript can’t break the HTML tag.

II think you will also find that the third parameter of the window.open needs to be either all on one line or if you specifically want it on separate lines then add '+ to the end of all lines of that parameter except for the last one.

If IE is squawking about whitespace (newlines, tabs) you could try minifying the code. Might be a good idea anyway. But I wouldn’t bother trying to hand edit all your source code. Keep the source human readable, and make minified copies for use.