I’m sorry if that question is obvious to solve, but I don’t know JavaScript yet but feels like it’s the only way to implement what my clients need for their website.
I want to redirect users with specific browser to the specific simplified page once they visit homepage and keep this redirection work everytime they click on homepage button. Basically what I want is a 301 redirect based on user-agent. I’ve tried many times but all I’ve got was an infinte redirection loop or no result at all.
function get_ya_browser(){
var ua = navigator.userAgent;
if (ua.search(/YaBrowser/) > 0) document.location.href='redirect-link.html';
return '';
}
How could I change this code to work? Would really appreciate any help.
2
Answers
Try – document.location.replace =’redirect-link.html’;
instead of document.location.href =’redirect-link.html’;
.location.replace() simulates a HTTP redirect
.location.href() simulates a mouseclick
If the code was part of
redirect-link.html
&&ua.search(/YaBrowser/) !== -1
, you will get an infinite loop.following code solved this problem: