Jesse
Jesse

Reputation: 351

ie7 "object doesn't support this property or method"

Can anyone explain why this is throwing an error in IE7? It's indicating the error is happening on the line with "var newStr....."

It's not happening in any other browser.

$(document).ready(function() {
    $('a[onclick*="_self"]').each(function() {
        var newOnclick = $(this).attr('onclick');
        var newStr = newOnclick.replace('_self','_parent');
        $(this).attr('onclick', newStr);
    });
});

Upvotes: 3

Views: 1416

Answers (2)

user626963
user626963

Reputation:

Try this:

$(document).ready(function() {
  $('a[onclick*="_self"]').each(function() {
    var newOnclick = $(this).attr('onclick').toString();
    var newStr = newOnclick.replace('_self','_parent');
    if($.browser.msie && parseFloat($.browser.version) == 7) {
       newStr = newStr.replace('onclick="function anonymous()
{
','onclick="');
       newStr = newStr.replace('}"','"');
    }
    $(this).attr('onclick', newStr);
    //$(this).unbind();
    //$(this).bind('click', function () { eval(newStr); });
  });
});

Upvotes: 0

Phil Rykoff
Phil Rykoff

Reputation: 12087

(Earlier versions) of IE cannot cast a function object to it's source as you request it. Thus, the strings cannot be exchanged that easily.

You can either replace the whole old "_self" function by a new _parent function, e.g.:

$('a[onclick*="_self"]').attr('onclick', function() { _parent-stuff });

or - I read your last comment and the second solution won't work for you as it would require changing the HTML of the body.

Upvotes: 1

Related Questions