How can I redirect the user from one page to another using jQuery?
jQuery is not necessary, and It is better than using For example:
| |||||||||||||||||||||
|
WARNING: This answer has been provided as a possible solution. Obviously, the pure JS approach is the right one.
| |||||||||||||||||||||
|
You don't need jQuery to do just that:
| |||||||||||||||||||||
|
All of these answers are correct, but I'll post this for those who might of run into the same strange issue I did. I was having an issue with In IE8 and lower location.href (or any & all variations of this lose this variable), which for secure sites is important to maintain, because testing for it (urlpaste'ing/ session / etc) can be helpful in telling whether a request is legitamate. (Note :: there are also ways to work-around / spoof these referer's, as noted by droop's link in the comments) My cross-browser fix is this simple function. Assuming you of course, are worried about losing Useage:
| |||||||||||||||||||||
|
I also think that location.replace(url) is the best way, but if you want to notify the search engines about you redirection (they don't analyze javascript to see the redirection) you should add the rel="canonical" meta tag to your website. Adding a noscript section with a html refresh meta tag in it, is also a good solution. I suggest you to use this javascript redirection tool to create redirections. It also have an IE support to pass the http referrer. A sample code without delay look like this:
| |||
|
You can do that without jQuery as:
And if you want only jQuery then you can do it like :
| |||
|
But if some one wants to redirect back to home page then he may use the following snippet.
It would be helpful if you have three different environments as development, staging, and production. You can explore this window or window.location object by just putting these words in Chrome Console or Firebug's Console. | |||||
|
On your click function just add
| ||||
|
first write properly you want to navigate within application for another link from your application for another link here is the code:
and if you want to navigate pages within your application then also i have code if you want. | |||
|
write the below code after php or html or jquery if in the middle of php or html then use tag
| |||
|
In javascript and jquery are using following code to redirect the one page to another page.
| ||||
|
So, the question is how to make a redirect page, and not how to redirect to a website? You only need to use Javascript for this. Here is some tiny code that will create a dynamic redirect page.
So say you just put this snippet into a
And if you go to that link it will automatically redirect you to google.com.
And that's how you make a Simple redirect page with javasctript | ||||
|
window.location.href = desireurl; e.g "https://www.google.co.in" | |||||
|
Use the following code:
| |||||||||
|
protected by Community♦ Mar 27 '12 at 17:03
This question is protected to prevent "thanks!", "me too!", or spam answers by new users. To answer it, you must have earned at least 10 reputation on this site.
window.location
is the same aswindow.location.href
, in terms of behavior.window.location
returns an object. If.href
is not set,window.location
defaults to change the parameter.href
. Conclude: Use either one is fine. – Shivan Raptor Aug 7 '12 at 7:03window.location.replace
and it's advantage over window.location.href, and my 300000+ users will be happier when they hit the back button, so it yes, it deserves a big +1 – Samuel Rossille Jan 28 at 22:36