我想有一个按钮,重定向到一个给定的网址,并打开在一个新的标签。这怎么可能呢?
这种行为只对插件可用,并且只能由用户进行配置。
使用 window.open代替 window.location打开新窗口或选项卡(取决于浏览器设置)。
window.open
window.location
您的小提琴不工作,因为没有 button元素可以选择。尝试 input[type=button]或给按钮一个 id和使用 #buttonId。
button
input[type=button]
id
#buttonId
添加 target = “ _ black”应该可以实现这一点:
<a id="myLink" href="www.google.com" target="_blank">google</a>
<BUTTON NAME='my_button' VALUE=sequence_no TYPE='SUBMIT' style="background-color:transparent ; border:none; color:blue;" onclick="this.form.target='_blank';return true;"><u>open new page</u></BUTTON>
这个按钮看起来像一个 URL,可以在一个新的选项卡中打开。
用这个:
<input type="button" value="button name" onclick="window.open('http://www.website.com/page')" />
对我有用,它会打开一个新的弹出窗口,而不是一个新的完整的浏览器或标签。你也可以添加变量来阻止它显示特定的浏览器特征,如下所示:
onclick="window.open(this.href,'popUpWindow','height=400,width=600,left=10,top=10,,scrollbars=yes,menubar=no'); return false;"
使用这个代码
function openBackWindow(url,popName){ var popupWindow = window.open(url,popName,'scrollbars=1,height=650,width=1050'); if($.browser.msie){ popupWindow.blur(); window.focus(); }else{ blurPopunder(); } }; function blurPopunder() { var winBlankPopup = window.open("about:blank"); if (winBlankPopup) { winBlankPopup.focus(); winBlankPopup.close() } };
它在 Mozilla、 IE 和 chrome 上运行良好,版本不到22,但是在 Opera 和 Safari 上不能工作。
我只是在表单标签下使用 target = “ _ black”,它在 FF 和 Chrome 中工作得很好,它在一个新标签中打开,但在 IE 中它在一个新窗口中打开。
您可以忘记使用 JavaScript,因为浏览器控制它是否在新的选项卡中打开。你最好的选择是这样做:
<form action="http://www.yoursite.com/dosomething" method="get" target="_blank"> <input name="dynamicParam1" type="text"/> <input name="dynamicParam2" type="text" /> <input type="submit" value="submit" /> </form>
无论客户端使用哪个浏览器,由于 target="_blank"属性,这将始终在新的选项卡中打开。
target="_blank"
如果所有您需要的是重定向没有动态参数,您可以使用与 target="_blank"属性的链接,如 Tim Büthe 所建议的。
试试这个 HTML:
<input type="button" value="Button_name" onclick="window.open('LINKADDRESS')"/>
在 javascript 中你可以做到:
window.open(url, "_blank");
我的首选方法的优点是不会在您的标记中嵌入 JavaScript:
CSS
a { color: inherit; text-decoration: none; }
超文本标示语言
<a href="http://example.com" target="_blank"><input type="button" value="Link-button"></a>
使用 javascript 在新选项卡中打开
<button onclick="window.open('https://www.our-url.com')" id="myButton" class="btn request-callback" >Explore More </button>
试试这个
<a id="link" href="www.gmail.com" target="_blank" >gmail</a>