Problem with Safari - What am I doing wrong

Discussion in 'Web Design and Development' started by noelister, Jul 16, 2006.

  1. noelister macrumors 6502

    Joined:
    Jan 15, 2005
    #1
    Hey everyone,

    I am trying reference an external JavaScript file on a page I am working on and Safari seems to have problems with it. However, Firefox displays the file fine... Could someone tell me what I am doing wrong?

    ---HTML

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1 TRANSITIONAL//EN"
    "http://www.w3.org/TR/xhtml11/DTDxhtml11.dtd">
    <html>
    <head>
    <title>Example</tilte>
    <script type="text/javascript" src="example.js"></script>
    </head>
    <body onload="process()">
    Hello there, here's a list of colors being displayed with an external JS file: <br />
    <div id="myDivElement" />
    </body>
    </html>

    ---END HTML

    ---JS FILE

    function process()
    {
    //create the HTML code with JavaScript
    var string;
    string = "<ul>"
    + "<li>Black</li>"
    + "<li>Red</li>"
    + "<li>Green</li>"
    + "</ul>";
    //obtain the a reference to the <div> element on the HTML page
    myDiv = document.getElementById("myDivElement");
    //Add content to the <div> element "myDivElement on the HTML page
    myDiv.innerHTML = string;
    }

    ---END JS FILE

    Thanks for any and all help,
    N
     
  2. zim macrumors 65816

    zim

    Joined:
    Jan 5, 2002
    #2
    Try this:

    <script language="JavaScript" type="text/javascript" src="example.js"></script>
     
  3. noelister thread starter macrumors 6502

    Joined:
    Jan 15, 2005
    #3
    That did not work... The page still renders blank in safari...:confused:
     
  4. tag macrumors 6502a

    tag

    Joined:
    Apr 29, 2005
    Location:
    PA, US
    #4
    Ok I uploaded the html and js to my site to test it out.

    If there is no text showing up at all, then perhaps the problem could be this?...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1 TRANSITIONAL//EN"
    "http://www.w3.org/TR/xhtml11/DTDxhtml11.dtd">
    You have a line break there. Perhaps Safari has problems recognizing this as valid code maybe, though netscape just seemed to not care and load the page fine. So if this is the case, make sure you edit your code so that this is 1 line and not 2.


    EDIT: Ok I didn't think I guess, since it does work in another browser, then there couldn't be problems with the js location or permissions, so I just deleted that idea.. still it could be the doctype problem above.
     
  5. noelister thread starter macrumors 6502

    Joined:
    Jan 15, 2005
    #5
    Thanks tag and zim. I found the problem. It was a typo, the closing title tag was misspelled "</tilte>". Every thing seems to be working as it should. I guess firefox ignores and or fixes these kind of things...:confused: Anyways thanks again for the quick responses.
     

Share This Page