Copy the Click Event in IE and Firefox and submit it to the new window (asp.net)

Source: Internet
Author: User

Let's take a look at the code that simulates the click event: Copy codeThe Code is as follows: <a href = http://www.jb51.net target = "_ blank" id = "aa"> OK </a>
<Script>
Var comment = document. getElementById ('A ');
If (document. all ){
Comment. click ();
} Else {// Firefox. If the onclick event is not defined in <a>, this section does not work for Firefox.
Var ev = document. createEvent ("MouseEvents ");
Ev. initEvent ("click", true, true );
Document. getElementById ("aa"). dispatchEvent (ev );
}

</Script>

In fact, I trigger a click event on a page mainly to open a new window when submitting a form. Others tend to ignore some basic knowledge, <form> In fact, this function has been provided,

We forget it.Copy codeThe Code is as follows: <form action = "/shopping/index" method = "post" id = "processorder" target = "_ blank" onsubmit = "return checkOrder ()">
<Input name = "button2" type = "submit" id = "button2" value = "" class = "ck_lijisn"/>
</Form>

This code can be submitted in a new window, but note that the button cannot be a button. If you use document. getElementById ("processorder"). submit () in the program, it cannot be implemented.

Submitted in a new window. Haha.

It seems that sometimes things are still traditional.

Related Article

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.