views:

22301

answers:

16

I am trying to get my jQuery functions to work on IE8. I am loading the library from google's servers (http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js). The $(function(){}) is never called. Instead, I get an error "Object expected". I opened the developer and ran "typeof $" in the console, and it came up as "undefined". I have tried going to other sites that I know use jQuery (jquery.com), and those all work, is there something I might be missing here?

+1  A: 

jQuery is not being loaded, this is not likely specific to IE8. Check the path on your jQuery include. statement. Or better yet, use the following to the CDN:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"&gt;
</script>
altCognito
Everything works in firefox, safari, and chrome. I can tell that the library is being downloaded, just not executed. I set a breakpoint on the line in the jquery file, and it came up saying that there is no executable code associated with the line.
A: 

Maybe you have inPrivate Filtering turned on?

Eduardo Molteni
A: 

I had the same problems.

i solved it verifing that IE8 was non correctly configured to reach the SRC url.

changeed this, it gone right. by Cris

+8  A: 

I was having a similar issue. Things worked in IE6, Firefox, and IE8 running in IE7 compatibility mode; but not in 'normal' IE8. My solution was to put this code in the header

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

As to why jquery isn't working in IE8 I'm unclear.

www.Flextras.com
Works, but I'm still very confused as to why it was broken in the first place!
TimS
that's hideous! it doesn't solve the problem; it just hacks around it, and it'll probably create a whole load of other issues. (IE7-compatibility mode isn't actually completely the same as IE7, it has bugs, quirks and glitches all of its own that don't appear either in normal IE7 nor IE8)
Spudley
If you have a better solution, please share. Many approaches to get things working in IE are hacks.
www.Flextras.com
A: 

I had a similiar issue with IE8. I find it so ironic that Microsoft is including JQuery in the latest versions of Visual Studio but their browser does not know how to interpret the javascript correctly. Here is some code (written by Stephen Walther is a Senior Program Manager at Microsoft) that will not run in IE8.... I downloaded and made Google Chrome my default browser and now my lightbox demo works great!. This is a very good tutorial on JQuery BTW - the link to the presentation is http://channel9.msdn.com/pdc2008/PC31/ and here is the code that IE8 chokes on

<script type="text/javascript">

    var photoView;

    function pageLoad()
    {
        $("#categories a").click(selectCategory);
        photoView = $create(Sys.UI.DataView, {}, {}, {}, $get("photoContainer"));
    }

    function selectCategory(e)
    {
        // Stop link from executing
        e.preventDefault();

        // Highlight selected link
        $("#categories a.selectedCategory").removeClass("selectedCategory");
        $(this).addClass("selectedCategory");

        // Invoke web service
        PhotoServices.PhotoService.GetPhotos($(this).attr("categoryid"), getPhotosComplete); 
    }

    function getPhotosComplete(photoData)
    {
        photoView.set_data(photoData);
        $("#photoContainer").litebox();
    }

</script>
lanativelea
A: 

I've run into this issue when trying to include jQuery from the CDN on a secure page. The weird thing was that it worked in every major browser EXCEPT ie8.

Thad
A: 

Write "var" before variables, when you define tehem. IE8 dies when there is no "var".

asd
A: 

OK! I know that jQuery is loading. I know that jQuery.textshadow.js is loading. I can find both of the scripts in Developer Tools.

The weird part: this code is working in the content area but not in the banner. Even with a dedicated fixIE.css. AND it works when I put the css inline. (That, of course, messes up FireFox.)

I have even put in a conditional IE span around the text field in the banner with no luck.

I found no difference and had the same errors in both jquery-1.4.2.min.js and jquery-1.2.6.min.js. jquery.textshadow.js was downloaded from the jQuery site while trying to find a solution to this problem.

This is not posted to the Website

Kyle
A: 

I had similar problems when trying to load jQuery from a script (by adding a script tag to the header) and calling it in the same script. Looked like some sort of timing issue, with jQuery not being loaded in time. I solved it by using putting a static script tag in the HTML code.

Tgr
+1  A: 

The solution is to upgrade to the latest version of jQuery. I had the exact same problem and upgraded to 1.4.2 and it all works fine again in IE8.

Seems to be totally backwards-compatible with all the jQuery 1.3.2 stuff I did as well so no complaints here!

Peter Burlingham
A: 

I realize it's an old question, Having recently run into this issue myself, I wanted to ask if you were having issues while in HTTPS and inline scripts using jQuery ie $(document).ready(...)?

In HTTPS it seems that IE8 attempts to interpret inline scripts before processing any external scripts.

My temporary fix/bandaid uses conditional tags for IE around the minified jQuery code inline on the page.

I'm going to attempt to move the suspected inline scripts to external script files as well to see if that does the trick.

Micah
Well, it would appear that a rewrite rule was kicking my rear...
Micah
A: 

Maybe you insert two scripts,it should be work.

<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"&gt;&lt;/script&gt;  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"&gt;/script&gt; 
Vadim Slutsky
A: 

I had the same issue. The solution was to add the link to the JQuery file as a trusted site in IE.

tou
A: 

The onload event does not always work on IE7/8 in <head> ... </head>

You can force it by adding an onload script at the end of your page before the tag as below.

<script> window.onload(); </script> </body>

Andy Piddock
A: 

Similar problem. The site works fine on IE8, but when I iframe the site some pictures disappear and I get an access denied on jquery-1.3.min.js Works perfectly well on IE7, IE9 or FF3.6

millebii
+1  A: 

There is another way to load jQuery from Google CDN (it uses google.load() function) and according to this answer it works both in Firefox and Internet Explorer.

Marek Grzenkowicz