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