简体   繁体   English

<a>在新窗口中打开。</a> <a>但是标准是_blank</a>

[英]Open <a> in a new window. But standard is _blank

I have a Drupal website. 我有一个Drupal网站。 I have a RSS feed with . 我有一个RSS供稿。 Ahref links with target blank. Ahref与目标空白链接。 But there is a bug in Drupal CMS. 但是Drupal CMS中有一个错误。 When i clicking on the links. 当我点击链接。 Than the link open in the same window and a new window. 比链接在同一窗口和新窗口中打开。

How can i fix this with javascript. 我该如何使用JavaScript修复此问题。 Can i make a script that open links with target blank in a new window. 我可以创建一个在新窗口中打开目标链接为空白的脚本吗? And open not in the same window? 并在不同的窗口中打开?

Thanks for helping 感谢您的帮助

check this http://www.pageresource.com/jscript/jwinopen.htm . 检查此http://www.pageresource.com/jscript/jwinopen.htm

note that u must call event.preventDefault() method to avoid default behavior. 请注意,您必须调用event.preventDefault()方法以避免默认行为。

  window.onload = function(){        
        var aTags = document.getElementsByTagName("a"); 
        for (atag in aTags)
        {
            atag.onclick = function(event){             
                 var target = atag.getAttribute("target");           
                 if ( target == "_blank")
                 {
                    var href = atag.getAttribute("href");
                    window.open(href,'mywindow','width=400,height=200')
                    event.preventDefault();
                 }
           };
        }
    };

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

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