简体   繁体   中英

Why doesn't this external JavaScript load?

I've been futzing with this for hours trying to figure out why codemirror.js won't load in any browser other than Firefox . Any ideas?

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head>
    <title></title> 
    <script src="CodeMirror/js/codemirror.js"></script> 

    <link href="Styles/Style.css" rel="stylesheet" type="text/css" />
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 

    <script type="text/javascript"> 
        $(document).ready(function () { $('#container-1').tabs(); });
    </script> 
    <style type="text/css"> /* (some css) */ </style>
</head><body>
<!-- (some stuff) -->
</body></html>

CodeMirror/js/codemirror.js

alert("LOL");

I tried the code in Firefox 3.6.3, Internet Explorer 8, Opera 10.53 and Safari 4.0.5, and it works just fine.

Note that the address to the script is relative, so if your page is at www.mydomain.com/content/pages/page.html , it will load the script from www.mydomain.com/content/pages/CodeMirror/js/codemirror.js , not www.mydomain.com/CodeMirror/js/codemirror.js .

One thing that you can improve is to add the type attribute to the tag:

<script src="CodeMirror/js/codemirror.js" type="text/javascript"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM