Sunday, 6 August 2017

php - How do I use a header location in jQuery?




Can I use a header location in jQuery for redirection or refresh?




Like in PHP:



header('location:www.google.co.in');
header("Refresh:1,url=home.php");


If not, what is the alternative way?


Answer



Headers are interpreted prior to the rendering of the document, and before jQuery is even loaded so these aren't an option. Instead, you can redirect the browser using document.location.




document.location.href = 'www.google.co.in';


For a jQuery approach you can use



$(location).attr('href', 'www.google.co.in');


however I would favor the plain javascript version.



No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...