Reputation: 5947
I have 20 links and I want to open first 10 in a separate window and the remaining in a separate second window. Issue is my all links are being opened in 20 tabs in a single window.Wrote following Javascript code.
function myFunction() {
window.open('http://localhost/sample/first.aspx', '1');
window.open('http://localhost/sample/second.aspx', '2');
window.open('http://localhost/sample/third.aspx', '3');
......
......
......
window.open('http://localhost/sample/twenty.aspx', '20');
}
then I tried this
function myFunction() {
window.open('http://localhost/sample/first.aspx', '1');
window.open('http://localhost/sample/second.aspx', '2');
window.open('http://localhost/sample/third.aspx', '3');
window.open('http://localhost/sample/eleventh.aspx', 'myWindow', "height=200,width=200",'1');
window.open('http://localhost/sample/twelfth.aspx', 'myWindow', "height=200,width=200",'2');
}
though this opens a new window but it over rides all the links and shows only one link(whichever is the last) opened.
Means,if we take this code as an example as it is written here, first 3 links open properly in 3 tabs in a single window,after that a window opens with having only 'localhost/sample/twelfth.aspx' opened in that new window.
what to do to resolve this issue and open specific number of links in separate tabs in a separate window?
Upvotes: 0
Views: 1223
Reputation: 297
To open link in new window
window.open('url', 'window name', 'window settings')
To open link in new tab
window.open('_link is here_', 'name');
Where 'name' :-
_blank - URL is loaded into a new window. This is default
_parent - URL is loaded into the parent frame
_self - URL replaces the current page
_top - URL replaces any framesets that may be loaded
you can use this.
Upvotes: 0
Reputation: 23
I'm fairly certain this isn't something that's controllable through javascript itself since this affects browser behavior. Looking through most browsers there's settings for how to treat links, especially new tab vs. new window.
So, without knowing with 100% certainty, I'd say no, it's not possible to do with just plain javascript.
Upvotes: 1