以编程方式在新标签页中打开html链接 [英] Programmatically open html link in new tab
问题描述
我最近注意到当您将链接或表单目标设置为_blank并单击/提交时,它会在所有主要浏览器的新选项卡中打开,但是当我使用javascript / jquery来单击/提交链接/表单时,它将其作为弹出窗口而不是标签打开,这种行为仅在Chrome,Firefox和IE中<= 8,而不是在IE 9 +中。因此点击此链接或提交按钮可用于新标签:
< a href ='http://google.com' id ='myLink'target ='_ blank'>
< form action ='http://google.com'id ='myForm'target ='_ blank'>
< input type ='submit'value ='go'/>
< / form>
但是,当这样做时,它会以弹出窗口的形式打开,所以大多数浏览器都会阻止它:
$('#myLink')。click();
$('#myForm')。submit();
任何人都知道这个解决方案或一些更好的解决方案吗?
编辑:我试图避免任何window.open()方法。
搜索引导我到这个页面:
//www.pageresource.com/jscript/jwinopen.htm
它解释了多个例子的不同之处。第二个例子是你正在寻找的。希望这有助于。
编辑 - 试试这个:
不使用`window.open`或`window.location.href` 打开新的窗口/标签。
I have recently noticed the when you set a link or form target to _blank and click/submit it, it opens in a new tab on all major browsers but when I use javascript/jquery to either click/submit the link/form, it opens it as a popup window instead of a tab, this behaviour is only in Chrome, Firefox and IE <= 8, not in IE 9+
So clicking on this link or submit button works for a new tab:
<a href='http://google.com' id='myLink' target='_blank'>
<form action='http://google.com' id='myForm' target='_blank'>
<input type='submit' value='go' />
</form>
But when doing this it opens as a popup so most browsers block it:
$('#myLink').click();
$('#myForm').submit();
Anyone know any workarounds for this or some better solution?
EDIT: I'm trying to avoid any window.open() methods.
A very quick Google search lead me to this page:
http://www.pageresource.com/jscript/jwinopen.htm
It explains the difference with multiple examples. The second example is what you are looking for. Hope this helps.
Edit- Try this one: Opening new window/tab without using `window.open` or `window.location.href`
这篇关于以编程方式在新标签页中打开html链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!