开发者

jQuery redirect not working in non-IE browsers

I'm trying to redirect all links to a particular page on our site to a secure connection using jQuery. This code works fine in IE, but it doesn't work in any other browser (tried it in Chrome, Firefox, and Safari). Any 开发者_Python百科idea why this wouldn't work?

$(function() {
    $(“a[href*=’enroll_now.aspx’]”).attr(“href”, “https://www.[redacted].com/enroll_now.aspx”);
});


I am not sure, but you're using those curly "MS Word Smart Quotes" instead of normal quotes " or '. I won't wonder if MSIE is more forgiving here than the decent browsers.

The correct piece of code should look like:

$(function() {
    $("a[href*='enroll_now.aspx']").attr("href", "https://www.[redacted].com/enroll_now.aspx");
});

Apart from this problem, this task is undoubtely better to be done in the server side (directly in source code) than in the client side (using Javascript). Javascript isn't that safe enough for this particular one-time-done task, clients can namely disable Javascript.


Try this:

$(document).ready(function(){
        $("a[href*='enroll_now.aspx']").attr("href", "https://www.redacted.com/enroll_now.aspx");
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜