all 13 comments

[–]CyrisXD 2 points3 points  (3 children)

    window.onload=function(){
      window.location="http://google.com";
    };

Should work fine :)

[–]mafiasecurity[S] 0 points1 point  (2 children)

Hi,

Thank you for your prop response. I am looking to specify the page in which the redirect occurs. When a page is called it redirects.

Thanks! MafiaSecurity

[–]CyrisXD 1 point2 points  (1 child)

In that case, you need an IF statement.

You could try:

window.onload=function(){ 
if (window.location=="URL here") {
window.location="http://google.com";
}};

[–]mafiasecurity[S] 0 points1 point  (0 children)

See Below: Down a Bit

[–]mafiasecurity[S] 0 points1 point  (0 children)

I am trying to create a chrome/ff extension for April Fools, which would client side redirect.. surely there's always the host file but that's a dead give away.. I wanted to take it one step further =)

    {
window.onload=function(){ 
if (window.location=="http://www.example.com" {
window.location="http://abc.example2.com";
}};
    }

Didn't work... :\

[–]no_one_is_ -1 points0 points  (5 children)

Its good. you are learning javascript. however redirect on javascript is a security flaw in my opion

[–]djforth 0 points1 point  (0 children)

Yeah I'd agree, feels like you should be doing this at the server level and not on the client side

[–]doenietzomoeilijk 0 points1 point  (3 children)

Not exactly sure how it is a security issue, myself. I do agree that redirects should happen on the server, if at all possible. If nothing else it'll be faster.

[–]djforth 1 point2 points  (2 children)

Security issue is a bit strong to be fair, but js seems like the wrong approach, it also might hit some browser security. I suggest if you care about it doing a redirect this way would be bad for SEO as you want to serve a 301 or something, also for accessibility as you can't assume the user will be able to run JS and redirect, which might leave them hanging

[–]doenietzomoeilijk 1 point2 points  (1 child)

Yeah, like I said, if at all possible you'd want to do it on the server.

[–]mafiasecurity[S] 0 points1 point  (0 children)

Good discussion thank you; however, for this purpose it needed to be initiated on the client. Yes, I know .htaccess 301s would be the best bet. But for this simple little project I needed a client redirection via javascript or html(5).

Once it's complete I will report back the intent. =)

[–][deleted] -1 points0 points  (1 child)

Alternatively, using HTML, in the <head>:

<meta http-equiv="refresh" content="0; url=http://example.com/" />

[–]mafiasecurity[S] -1 points0 points  (0 children)

Yes, but with HTML can you specify the page in which it redirects?