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);
});
});
(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, eg:
$('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.
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); });
});
});
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.