简体   繁体   中英

How do I open a link in a new tab but stay on the same page using HTML code?

试试这个代码...

<a href="http://example.com/"  target="_blank">Open New Link</a>

您可以尝试使用 window.open 打开新窗口并返回 false 以防止默认操作。

<a href="http://example.com/"  target="_blank" onclick="window.open( 'http://example.com/' ); return false;">Open New Link</a>

You can use this script. First, go to theme editor and find the footer.php file inside of the body section paste the script.

good luck

 <script type="text/javascript"> jQuery(document).ready(function($) { $('a').each(function() { var a = new RegExp('/' + window.location.host + '/'); if(!a.test(this.href)) { $(this).click(function(event) { event.preventDefault(); event.stopPropagation(); window.open(this.href, '_blank'); }); } }); }); </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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