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. Simply do :
|
|||||||||||||||||||||
|
You don't need jQuery to do just that:
|
|||||||||||||||||||||
|
It would help if you were a little more descriptive in what you are trying to do. If you are trying to generate paged data, there are some options in how you do this. You can generate separate links for each page that you want to be able to get directly to.
Note that the current page in the example is handled differently in the code and with CSS. If you want the paged data to be changed via AJAX, this is where jQuery would come in. What you would do is add a click handler to each of the anchor tags corresponding to a different page. This click handler would invoke some jQuery code that goes and fetches the next page via AJAX and updates the table with the new data. The example below assumes that you have a web service that returns the new page data.
|
|||
|
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: |
|||||||||
|
This version works well with jQuery 1.6.2. |
||||
|
You can do that without jQuery as:
And if you want only jQuery then you can do it like :
|
|||
|
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:
|
|||
|
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.
|
||||
|
JQuery is not needed you can do this:
|
|||
|
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