1

I had a problem with some functionality working in all browsers except for Safari, and I have reduced the problem down to this.

In my page I have the following script declarations at the end of my body element:

<script type="text/javascript" src="../../Scripts/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery-ui-1.8.11.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.ui.autocomplete.html.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.textchange.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.reveal.js"></script>
<script type="text/javascript" src="../../Scripts/mainScript.js"></script>

Then inside the mainScript.js file, I have put the following code:

$(function () {
  alert("found");
});

In all other browsers, it displays a message box, but in Safari it does nothing.

Safari's javascript debugger lists the script, and can see the contents, but for some reason it's not included.

I found this problem since I tried to call a function in mainScript.js from an inline script inside the html page (the inline script was defined below the mainScript.js definition), and the Safari debugger complained that the function was not found anywhere.

What have I done wrong here, and why does not Safari include this script. All the jquery scripts are included and are working fine.

2 Answers 2

1

Your code seems good.

I tried with this code

<!DOCTYPE html>
<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <h1>Test</h1>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                alert("Test");
            });
        </script>
    </body>
</html>

and it works fine (Safari 5.0.5 7533.21.1 on Windows 7).

A couple of questions:

  1. Have you tried calling your function manually from the Error Console? Does it work?
  2. If you place a simple alert("Test."); outside of the document ready function, is it displayed?
  3. If you call jQuery's function from the Error Console, what do you get? Do they work?
Sign up to request clarification or add additional context in comments.

1 Comment

Fell really stupid now. Just after looking at this for a long time, and posting this question I found the reason for this. There was something else in script that gave an error, so the entire script file got skipped. the code { class: 'Test'} works in all browsers, except for Safari. It fails because class is a reserved word. So I guess Safari is right in calling the error here, and the other browsers are just trying to be nice :)
1

The problem was found elsewhere in mainScript.js.

{ class: 'someclass' } was sent as parameter to some method, and class is a reserved word.

This should probably have given errors in other browsers as well, but they gladly ignored it and kept on going.

The fix was simply to change it to { 'class': 'someclass' }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.