简体   繁体   English

有没有办法强制在选项卡中打开“onclick”新窗口?

[英]Is there a way to force an “onclick” new window to open in a tab?

Related but dormant: Javascript to open URL within a new Tab and a number of others... 相关但休眠: 在新标签和其他一些标签中打开URL的Javascript ...

I have a client who insists that a particular link needs to open in a new tab, rather than a window. 我有一个客户坚持要求特定链接需要在新标签页而不是窗口中打开。 It's being generated by the "onclick" event of a form submission button, called by a jquery function in the php document that looks like this: 它是由表单提交按钮的“ onclick”事件生成的,该事件由php文档中的jquery函数调用,如下所示:

function newTabLink($element,$url) {        

    ?><script language="JavaScript" type="text/javascript">//<![CDATA[
        jQuery(document).ready( function() {
            jQuery('<?php echo $element; ?>').click( function() {
                window.open( "<?php echo $url; ?>",'_blank' );
                } );
            } );
            //]]></script><?php     
}

I also have a css declaration in my stylesheet which tries to force new windows into tabs rather than new windows: 我的样式表中也有一个css声明,试图强制新窗口进入选项卡而不是新窗口:

* { target-new: tab !important; }

The css target-new property seems to work in IE9, forcing the popup into a tab. css target-new属性似乎可以在IE9中使用,将弹出窗口强制放入选项卡中。 FF and Chrome/Safari both default to tabbed browsing, even without that property set. 即使没有设置该属性,FF和Chrome / Safari也默认为选项卡式浏览。 But how can I force IE8 and 7 to open this particular link in a tab? 但是,如何强制IE8和7在选项卡中打开此特定链接?

Any ideas? 有任何想法吗?

You cannot reliably do that. 你无法可靠地做到这一点。 As you note, Firefox and the WebKit browsers can be configured to open new windows however the user wants. 如您所述,可以将Firefox和WebKit浏览器配置为根据用户需要打开新窗口。 I hope that IE9 can be configured to override the behavior of that "style". 希望 IE9可以配置为覆盖“样式”的行为。 ( edit — that appears to be a draft CSS3 thing - I hope personally that it dies in committee.) 编辑 -这似乎是CSS3的草稿-我个人希望它在委员会中死亡。)

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

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