简体   繁体   English

有没有办法确保target = _blank链接在前台打开?

[英]Is there a way to make sure target = _blank links open in foreground?

For some browsers (and depending on settings), links with target = "_blank" seems to open in the foreground, but for a lot of others it seems to open in the background. 对于某些浏览器(并取决于设置),target =“ _blank”的链接似乎在前景中打开,但是对于其他许多浏览器,它似乎在后台中打开。

In my case opening in the foreground is what a user intends when she/he clicks on the link, so it would be nice if there is a way to ensure that. 在我的情况下,打开前景是用户单击链接时的意图,因此,如果有一种方法可以确保这一点,那就太好了。 Is there a way to do this? 有没有办法做到这一点? Thank you. 谢谢。

There is no way to make sure these links open in the foreground. 无法确保这些链接在前台打开。 This is something the browsers arrange and there is nothing you can change about it. 这是浏览器安排的,您无法对其进行任何更改。

You could however open the link in the same window by leaving out the target attribute, that will ensure the people clicking the link get to see the page immediatly. 但是,您可以通过省略target属性在同一窗口中打开链接,这将确保单击链接的人员可以立即查看页面。 In a way this is also 'nicer' since it leaves the choice of opening the link in a new window to the user itself. 从某种意义上说,这也是“更好”的选择,因为它使用户可以在新窗口中打开链接。

You can try using window.focus() to bring the new window to the front. 您可以尝试使用window.focus()将新窗口置于最前面。 You may do it on the opened document, using jquery, with: 您可以使用jquery在打开的文档上执行以下操作:

$(function() {
    window.focus();
});

or from the original document: 或来自原始文件:

var newWindow = window.open(url);
window.setTimeout(function() { newWindow.focus(); }, 1000);

The setTimeout is needed to allow time for the window to be actually created by the browser. 需要setTimeout,以便留出时间让浏览器实际创建窗口。 There may be a cleaner method to achieve this, but the setTimeout should do it. 可能有一种更简洁的方法可以实现此目的,但setTimeout应该可以做到这一点。

暂无
暂无

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

相关问题 有没有办法只为重定向的链接制作“target='_blank'”? - Is there a way to make "target='_blank'" only for the redirected links? 覆盖所有目标 =“_blank”以在同一页面上打开链接的最佳方法 - Best way to overwride all target=“_blank” to open links on same page 如何在同一iframe中使用target =“ _ blank”在iframe中打开链接? - How to open links in an iframe with target=“_blank” in the same iframe? 如何使用外部浏览器在WebView中打开目标_blank链接 - how to open target _blank links in WebView with external browser 始终在同一窗口(而不是父窗口)中打开target =“_ blank” - Make that target=“_blank” open always in the same window (not parent window) 将target =“blank”添加到使用javascript的链接 - Adding target=“blank” to links with javascript 所有链接的自动 {target=_blank} - Automatic {target=_blank} for all links Google Chrome窗口中iframe内的iframe无法打开带有target =“_ blank”的链接 - iframes within iframes in Google Chrome windows won't open links with target=“_blank” HTML嵌入式PDF所有链接覆盖以在新选项卡中打开(target =“_ blank”) - HTML embedded PDF all links override to open in a new tab (target=“_blank”) Firefox是否会“正确”打开JavaScript加载页面时添加了target =“ _ blank”属性的链接? - Will Firefox not “correctly” open links with a target=“_blank” attribute added on page load by JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM