English 中文(简体)
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 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");
});




相关问题
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,...

Browser-friendly way to simulate anchor click with jQuery?

I m trying to simulate a click on an anchor tag using jQuery. I ve been digging around StackOverflow and Google for a while and haven t found anything that works on all of the browsers I m testing. So ...

Widescreen check on normal screen

I work normal screen and I develop some web application. When the application goes on widescreen some of the pages looks weired. Is there any way I can view my web page as it looks in Widescreen on my ...

Cross-browser development

I m developing a web application for a new service, starting from Firefox 3.5. The interface design is tableless, only using divs + CSS & performance-blessed practices. Now, while being ...

热门标签