简体   繁体   中英

Force Browser to open new Tab

Greetings my fellow coders!

I need some help:

I created 2 sites which allow users to create "ClusterLinks" - Links that are related to a database in which multiple, user added links are saved. You can visit this page at luckycrew.net

(NOTE: At this time, only the "permanent" option works properly)

You can try it out yourself or use this link I just prepared to show you the principe: The Cluster Gate

The site is really self explaining.

However, if I use a different browser than firefox (which works perfectly for my purpose here), the first link opens up in a new tab as intended while later following links appear in a window-style popup which is very ugly and not what I'm trying to achieve here.

The code for the opening of the link is this:

$("#openLink").click(function(){     
for(var i=0;i<theLinks.length;i++){
    var elim = theLinks[i].replace(/\"/g,'');  //eliminate double quotes
    window.open(elim,'_blank');
}

});

From researching I found out I could use JQuery's click() function directly on links in the HTML-DOM, but as I expected this had not the effect I wanted (and did not work correctly at all)....

An important note here is that I can't use AJAX here for reasons of the implementation.
(I can post snippets from my php file if this really was needed)

If anybody could help me I was really thankfull, also if you have any tipps for me to improve usability and safty of the page!

EDIT: I have tryed creating a mouse click event with

var a = window.document.createElement("a");
     a.target = '_blank';
     a.href = elim;

// Dispatch fake click
    var e = window.document.createEvent("MouseEvents");
    e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    a.dispatchEvent(e); //hope I got this example right

However, for Opera it still openes all tabs after the first in pop-up windows. I know there is an option in the browser settings with which you can edit the browser behaviour on links. Unfortunately I can't set it for the user and I cannot imposition each user to do this. Still worth a try.

Try replacing '_blank' with a name. That will open all links in the same new tab opened. Should work in most browsers.

So:

    window.open(elim,'SomeNameHere');

If you use

window.open('','');

It should work.

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