A summary of how to open a hyperlink in a new window

Source: Internet
Author: User

1. Open the link on the entire webpage in a new window: add the link to the head

<Base target = "_ blank">

2. Open all links in a DIV in a new window:

Add in body

Copy codeThe Code is as follows:
<Script language = "JavaScript">
<! -
Var anchors = document. getElementById ("DIV name"). getElementsByTagName ("");
For (var I = 0; I <anchors. length; I ++)
{Var anchor = anchors? I ==anchor.tar get = "_ blank ";}
//->
</SCRIPT>


Added whether or not to open the current window
Copy codeThe Code is as follows:
// Control the hyperlink to open in a new window
Var tar = "";
Tar = "_ blank ";
Var urls = document. getElementsByTagName ("");
For (var I = 0; I
{
If(urls+ I }.tar get! = "_ Self "){
Urls[ipolic.tar get = tar;
}
}

3. Open the specified link in a new window:

Open in the original window: <a href = "http://www.baidu.com"> Baidu </a>
Open in the new window: <a tager = "_ blank" href = "http://www.baidu.com"> Baidu </a>

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.