简体   繁体   中英

Open links in a new window

I have a div called 'divLinks'

I want all links inside the divLinks to open in a new window.

How can I write a cross-browser effective script to achieve this?

Assuming "a div called 'divLinks'" means that the div has an id of 'divLinks'...

var links=document.getElementById('divLinks').getElementsByTagName('a'), 
    len=links.length, i;
for (i=len; i--;) { links[i].target='my_external_window'; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM