How to open the Javascript control page link in a new window

Source: Internet
Author: User

The first method is implemented using jquery. The principle is to first find the external link in the site and add the target = _ blank attribute to the link. The Code is as follows:
Jquery opens in a new window
 Copy codeThe Code is as follows:
$ ("A [href * = 'HTTP: // ']: not ([href * ='" + location. hostname + "']), [href * = 'https: //']: not ([href * = '" + location. hostname + "'])")
. AddClass ("external ")
. Attr ("target", "_ blank ");

Js opens in a new window
 Copy codeThe Code is as follows:
Var aTag = document. getElementsByTagName ('A ');
For (I in aTag ){
Atagpoliciunc.tar get = '_ blank ';
}

Html Method
Add
The Code is as follows: copy the Code <base target = '_ blank'/>
You can open all pages in a new window.

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.