The Javascript control page Link is opened in a new window.

Source: Internet
Author: User

Today, I was told by A friend that I didn't add A window in the title of "A". How can I open all the pages on the page on the new page? I found several practical methods, my personal favorite is the last method.

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

The Code is as follows: Copy code

$ ("A [href * = 'HTTP: // ']: not ([href * ='" + location. hostname + "']), [href * = 'https: //']: not ([href * = '" + location. hostname + "'])")
. AddClass ("external ")
. Attr ("target", "_ blank ");

Js opens in a new window

The Code is as follows: Copy code

Var aTag = document. getElementsByTagName ('A ');
For (I in aTag ){
Atagpoliciunc.tar get = '_ blank ';
}


Html Method

Add

The Code is as follows: Copy 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.