[英]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.