문제

So, I have been learning some Javascript, and I came across the:

window.location = "website goes here.."; 

Now I have now learned that this could be used to redirect the user, I remember long ago i wanted so much to know how I can redirect users, without anchor tags and header(location:) since i couldn't use header after headers been sent.

SO I ask you guys, what are the disadvantages of using this Javascript to deal with redirecting my users after a if statement for example, or are there simply none.

Thanks

도움이 되었습니까?

해결책

If the user has JavaScript disabled, your redirect won't work.

Personally, I start my PHP code with ob_start(), then I can use header wherever I want :p

다른 팁

A possible disadvantage is that the User can disable Javascript. You can either use PHP, or you can use <meta http-equiv="refresh" content="0; URL='URL Here'" />.

I would say the primary problem with using javascript to redirect a user is that the redirect is not guaranteed. So for sensitive redirects that are important one should use header() or something that you know will work. If the redirect is simply an added bonus for your user then using javascript will work just fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top