Refti
Refti

Reputation: 755

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?

Upvotes: 2

Views: 432

Answers (1)

Dagg Nabbit
Dagg Nabbit

Reputation: 76736

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'; }

Upvotes: 1

Related Questions