开发者

Is there a way to force an "onclick" new window to open in a tab?

开发者 https://www.devze.com 2023-01-24 06:06 出处:网络
Related but dormant: Javascript to open URL within a new Tab and a number of others... I have a client who insists that a particular link needs to open in a new tab, rather than a window. It\'s being

Related but dormant: Javascript to open URL within a new Tab and a number of others...

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:

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:

* { target-new: tab !important; }

The css target-new property seems to work in IE9, forcing the popup into a tab. FF and Chrome/Safari both default to tabbed browsing, even without that property set. But how can I force IE8 and 7 to open this particular link in a tab?

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. I hope that IE9 can be configured to override the behavior of that "style". (edit — that appears to be a draft CSS3 thing - I hope personally that it dies in committee.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号