Window. Location. href and window. Location. Replace

Source: Internet
Author: User

When talking about the differences between the two methods, we need to combine the mechanisms of window. History. Go (-1); wondow. History. Back.

The two methods determine the page to jump to based on the request recorded by the server.

 

Window. Location. href ("test. jsp"); is a jump request sent to the server

Window. Location. Replace ("test. jsp"); is a jump that does not send a request to the server.

 

Therefore, window. History. Go (-1); wondow. History. Back (); works with window. Location. href ("test. jsp"); Okay is used.

 

Example of the following three pages

 

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> new document </title> <br/> <meta name = "generator" content = "editplus"> <br/> <meta name = "author" content = ""> <br/> <meta name = "keywords" content = ""> <br/> <meta name = "Description" content = ""> <br/> </pead> <br/> <body> <br/> This is 1 JSP <br/> </body> <br/> </ptml> <br/>

 

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> new document </title> <br/> <meta name = "generator" content = "editplus"> <br/> <meta name = "author" content = ""> <br/> <meta name = "keywords" content = ""> <br/> <meta name = "Description" content = ""> <br/> </pead> <br/> <body> <br/> This is 2 JSP <br/> <input type = "button" value = "go 3 JSP by window. location. replace "onclick =" window. location. replace ('3. JSP '); "> <br/> <input type =" button "value =" go 3 JSP by window. location. href "onclick =" window. location. href ('3. JSP '); "> <br/> </body> <br/> </ptml> <br/>

 

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> new document </title> <br/> <meta name = "generator" content = "editplus"> <br/> <meta name = "author" content = ""> <br/> <meta name = "keywords" content = ""> <br/> <meta name = "Description" content = ""> <br/> </pead> <br/> <body> <br/> This is 3 JSP <br/> <input type = "button" value = "back by window. history. go (-1) "onclick =" window. history. go (-1); "> <br/> <input type =" button "value =" back by window. history. back () "onclick =" window. history. back (); "> <br/> </body> <br/> </ptml> <br/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.