开发者

Problem with script execution in Safari

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.


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?


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' }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜