-2

I have a standard piece of HTML but cannot get jQuery to work on IE. I tried IE10 and IE11, as well as IE8 and 9 emulated in IE10.

I even tried using the code from HTML5Boilerplate. I am testing for jquery and is not loaded.

Code works in all other browsers. I am running this on my local, not on a server.

<!DOCTYPE html>
<html>

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>

<body>

    <script type="text/javascript">
        if (window.jQuery) {
            // jQuery is available.
        } else {
            console.log("-- no jquery --");
        }
    </script>

</body>

</html>

Why can't I get this to work in IE ?

I get -- no jquery -- SCRIPT5007: The value of the property '$' is null or undefined, not a Function object in the console.

Also, if I type jQuery().jquery in the console, I get undefined.

Network tab is not displaying any errors.

bg17aw
  • 2,818
  • 1
  • 21
  • 27
  • Why is the cdn version commented out? – Seth Nov 22 '14 at 21:43
  • So in IE console shows `-- no jquery --`? – A. Wolff Nov 22 '14 at 21:43
  • 1
    Are you sure that "js/jquery-1.11.1.js" exists? And if yes, have you tried on other browsers? – Dim13i Nov 22 '14 at 21:49
  • sorry, I copy pasted a test version where I tried loading from local file instead of CDN. I am trying to edit to change the code to just CDN – bg17aw Nov 22 '14 at 22:02
  • @bg17aw Well, I don't see why this shouldn't work. Does it work on other browsers? – Dim13i Nov 22 '14 at 22:05
  • I thought it is obvious I did try other browsers. I'll update the question. Did you try this in IE before downvoting without explanation? – bg17aw Nov 22 '14 at 22:08
  • Are you testing this from your desktop or is the html file loaded from a web server. If it is not loaded from web server your css and javscript will not load externally in internet explorer. If you are running from a web server then you have a path problem. – Larry Lane Nov 22 '14 at 22:08
  • 2
    So what happen??? Error in console? Message in console? Could it be cache issue? Network tab? Javascrpit disabled? Etc... You have to debug it on your side – A. Wolff Nov 22 '14 at 22:08
  • Sidenote: you cannot "emulate" older versions of IE from within IE. Those "modes" are only designed as fallbacks for older websites, not for emulating. That's why MS provides free virtualization tools for proper testing: https://www.modern.ie/en-us/virtualization-tools – Sparky Nov 22 '14 at 22:10
  • Also if you use the cdn link your sytax is incorrect you do not have the script tags enclosed with < > properly. – Larry Lane Nov 22 '14 at 22:11
  • 2
    @LarryLane, his `script` tags look fine to me. – Sparky Nov 22 '14 at 22:15
  • 2
    If you're testing this locally and not on a server, change `src="//ajax.googleapis.com` to `src="http://ajax.googleapis.com` – j08691 Nov 22 '14 at 22:15
  • @LarryLane Can you post the correct code? Thanks – bg17aw Nov 22 '14 at 22:17
  • 1
    What @j08691 said. Page needs to be online in order for you to leave off the `http:` scheme. Pages on your local hard drive will not work without a `http:` or `https:` scheme. – Sparky Nov 22 '14 at 22:18
  • @Sparky, they seem to work in other browsers. Why is that? – bg17aw Nov 22 '14 at 22:21
  • Other browsers are better? If it's local, then the scheme is assumed to be `file:`, which breaks it. Check your console errors for this and see: http://stackoverflow.com/a/7818464/594235 – Sparky Nov 22 '14 at 22:22
  • @Sparky, I updated the question, page runs on my local, not from a server. I posted the console errors. However, everything works in other browsers. – bg17aw Nov 22 '14 at 22:25

1 Answers1

3

Quote OP:

I am running this on my local, not on a server

Then you need to specify a scheme, otherwise the browser may assume that src="//domain.com/script.js" is src="file://domain.com/script.js", which will break since you're not hosting this resource locally.

References:

Community
  • 1
  • 1
Sparky
  • 98,165
  • 25
  • 199
  • 285
  • This indeed seems to be the problem. It was confusing as it worked in Chrome and FF. Also, I got no errors in the Network tab in IE. – bg17aw Nov 22 '14 at 22:30
  • @bg17aw - isn't this what I told you to try in the comments? – j08691 Nov 22 '14 at 22:39
  • 1
    @j08691, can I accept a comment? Not sure what you mean. – bg17aw Nov 23 '14 at 09:33
  • @bg17aw, [I already commented on that under the OP](http://stackoverflow.com/questions/27082846/not-able-to-load-jquery-in-internet-explorer/27083246?noredirect=1#comment42675593_27082846). Every browser is different... some work better than others and some follow coding standards better than others. See [this SO answer](http://stackoverflow.com/a/11372220/594235) and [the W3 spec](http://www.w3.org/TR/url/#resolve-a-string-as-a-scheme-relative-url) – Sparky Nov 23 '14 at 16:42