SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,808
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)

    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:
    Code:
    <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?




    .

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,053
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    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.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,789
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •