Js click the button to jump to the page code

Source: Internet
Author: User

In the webpage, the button does not have the attribute of tag a. If we want to add a jump event to the button, we can click the jump js on The onclick event, below I will introduce some common methods.

How can I jump to another page by clicking the button? We may need this in website production, because sometimes we need this effect, especially when we make a button into an image and click an image to jump to a new page, how can this problem be achieved?

This effect can be achieved through onclick = "window. location = 'new page.

1. directly jump to the original form using

The Code is as follows: Copy code

Window. location. href = "the page you want to jump ";

2. Open the page in the new form:

The Code is as follows: Copy code

Window. open ('page you want to jump ');

Window. history. back (-1); return to the previous page


The code is:

The Code is as follows: Copy code

<Input type = "submit" name = "Submit" value = "agree" onclick = window. open (http://www.bKjia. c0m/)>

If you want to verify that the input amount is filled in when you click the button to submit, what should you do? When the user name is entered or other fields are empty, click the button to do not submit. You can follow the methods below.

The Code is as follows: Copy code

<Input type = "submit" name = "submit" onclick = "open ()">

<Script language = javascript>
Fuction open (){

If (! Document. form_name.username.value ){

Alert ("Enter the user name! "); Document. form_name.username.focus (); return false;

} Else document. form_name.action = "aaa.htm ";

}
</Script>

In this case, when the value is null, the button will not jump to another page? In this way, the effect is achieved.


JS jump page reference code

The Code is as follows: Copy code

First:
<Script language = "javascript" type = "text/javascript">
Window. location. href = "login. jsp? Backurl = "+ window. location. href;
</Script>
Second:
<Script language = "javascript">
Alert ("return ");
Window. history. back (-1 );
</Script>
Third:
<Script language = "javascript">
Window. navigate ("top. jsp ");
</Script>
Fourth:
<Script language = "JavaScript">
Self.location+'top.htm ';
</Script>
Category 5:
<Script language = "javascript">
Alert ("illegal access! ");
Top. location = 'xx. jsp ';
</Script>

===== Jump to other pages through the pop-up selection box in javascript ====
<Script language = "javascript">
<! --
Function logout ()...{
If (confirm ("are you sure you want to log out of your identity? Yes-Select OK, no-select cancel "))...{
Window. location. href = "logout. asp? Act = logout"
}
}
-->
</Script>
 
===== Jump to other pages through a prompt box in javascript ====
<Script language = "javascript">
<! --
Function logout ()...{
Alert ("are you sure you want to cancel your identity? ");
Window. location. href = "logout. asp? Act = logout"
}
-->
</Script>

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.