简体   繁体   English

强制浏览器打开新标签页

[英]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. 我创建了2个站点,允许用户创建“ ClusterLinks”-与数据库相关的链接,在该数据库中保存了多个用户添加的链接。 You can visit this page at luckycrew.net 您可以在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. 但是,如果我使用的浏览器与firefox不同(此浏览器非常适合我的目的),则第一个链接将按预期在新选项卡中打开,而随后的后续链接将出现在窗口样式的弹出窗口中,这非常丑陋,而不是我想要的。试图在这里实现。

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).... 通过研究,我发现可以直接在HTML-DOM中的链接上使用JQuery的click()函数,但是正如我期望的那样,这并没有达到我想要的效果(并且根本无法正常工作)。

An important note here is that I can't use AJAX here for reasons of the implementation. 这里重要的一点是,出于实现的原因,我在这里不能使用AJAX。
(I can post snippets from my php file if this really was needed) (如果确实需要,我可以从我的php文件中发布摘要)

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. 但是,对于Opera,它仍会在弹出窗口中的第一个之后打开所有选项卡。 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. 尝试用名称替换“ _blank”。 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. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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