JAVASCRIPT-based WEB page Jump and cross-page value passing _ javascript skills

Source: Internet
Author: User
On a WEB page, we usually use LINK, BUTTONLINK, IMGLINK, and so on to jump to the page. the user clicks somewhere and then jumps directly to the browser. But sometimes, when an event is triggered, we need to do some operations first and then jump. At this time, we need to use JAVASCRIPT to implement this jump function.
The specific practices are as follows:
1. Jump to the new page and open it in the new window:

The Code is as follows:


Function gogogo ()
{
// Do someghing here...
Window. open ("test2.html ");
}


Window is a javascript Object. You can use its open method. Note that if the page is not a relative path, add http: //, for example:

The Code is as follows:


Function gogogo ()
{
Window. open ("http://www.google.com ");
}


2: Jump to the page:

The Code is as follows:


Function totest2 ()
{
Window. location. assign ("test2.html ");
}


If you can directly use location. assgin (), but window. location. assign () seems more reasonable. The assign () method of the location object of the current window is used.
In addition, the location object also has a method replace () which can also be used for page Jump. The difference between this method and assign () is as follows:
The replace () method does not generate a new record in the History object. When this method is used, the new URL will overwrite the current record in the History object.

Next we will learn how to transfer the value during page Jump, when using window. when open () opens a new page, the browser will think that there is a relationship between the two windows, so there is a window in the window object of the current window in the new window to be opened. opener attribute. This value contains a reference to open a window. Therefore, you can obtain this value and reference the value of the object on the previous page. The example is as follows:

The Code is as follows:




Test1

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.