Common JavaScript tips

Source: Internet
Author: User

Javascript is a good scripting language for Dynamic Interaction. Below are common JavaScript techniques I have summarized.
(1). Reference in the HTML page:
<Script language = "JavaScript">... </SCRIPT> // method 1
<Script language = "JavaScript" src = "JS file path (usually relative path)"/>

(2) Add to favorites: <a href = "javascript: window. external. addFavorite (location. href, document. title) "> Add to favorites </a> where location. href indicates the current page, document. title refers to the text displayed to the user (for convenience of memory) when added to the favorites.

(3) On the Asp.net server side, click OK and return to the previous page: reponse. write ("<SCRIPT> alert ('xxx'); history. go (-1); </SCRIPT> ");

(4) Save the page as: <a href = "#" onclick = "document.exe ccommand ('saveas')"> save it as </a>

(5) Click "enter" on the page, which is equivalent to triggering a button:

Function document. onkeydown ()
{
If (event. keycode = 13) // note the case sensitivity and determine whether to press Enter.
{
Document. getelementbyid ("btnok"). Click (); // btnok is the server-side control
Return false; // be sure to have
}

}
/* If the text box for receiving passwords is a client control, you can also define it as follows, and then do the following:
// Call <input id = "PWD" onkeydown = "enterdown (Button Object Name)"/>
Function enterdown (OBJ)
{
If (event. keycode = 13)
{
OBJ. Click ();
}
}
*/

(6) A new window is displayed: <a href = "#" onclick = "window. open ('keeppasswordonpageaftersubmit. aspx ',' _ blank ', 'height = 500, width = 100, toolbar = No, menubar = No, location = no') "> open </a>

(7) When deletion or closure is enabled, a prompt dialog box is displayed: <input id = "button3" type = "button" value = "button" onclick = "javascript: if (confirm ('do you want to close? ') Window. Close (); "/> </div>

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.