Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After upgrading to jQuery 1.6.2, globalEval throws an error when trying to execute javascript on page

I upgraded from jQuery 1.4.2 to 1.6.2 and now I get error(in IE). I have JavaScript on the page that gets executed by jQuery globalEval() function

// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
    if ( data && rnotwhite.test( data ) ) {
        // We use execScript on Internet Explorer
        // We use an anonymous function so that context is window
        // rather than jQuery in Firefox
        ( window.execScript || function( data ) {
            window[ "eval" ].call( window, data );
        } )( data );
    }
},

In IE the call throws exception:

"Error: Could not complete the operation due to error 80020101."

The data parameter that get executed is javascript variables on page surrounded by <!-- -->

<!-- 
var id = \"ctrl90900\";

var url = \"myur.com/blah.html\";

-->

I'm using IE9, and jQuery 1.6.2 Not sure why this would cause an error.

like image 759
dev.e.loper Avatar asked Aug 15 '11 23:08

dev.e.loper


2 Answers

If there is any error at all in a script passed to execScript, as far is Internet Explorer is concerned, it will report a 80020101 instead of the original error.

So, also check for missing semicolons and JS features not supported by IE.

For short code passages, i found the most effective debugging technique was to comment out parts of code and see if the error still turns up. If it doesn't, examine the code block that was just commented out for above errors.

like image 83
cmc Avatar answered Oct 26 '22 01:10

cmc


It might be the commenting of the code, which is invalid JavaScript and unnecessary in this day and age.

You can strip it out with this regex...

$.globalEval(str.replace(/<!--\s*([\s\S]*?)\s*-->/, '$1'));

jsFiddle.

like image 28
alex Avatar answered Oct 25 '22 23:10

alex