【问题标题】:HTML a href with target set to "_blank" without moving to the opened pageHTML a href 目标设置为“_blank”而不移动到打开的页面
【发布时间】:2019-06-07 15:11:03
【问题描述】:

我想创建一个目标属性设置为空白的标签,但实际上并没有将我移动到打开的页面,而是停留在打开它的页面上。

【问题讨论】:

标签: html hyperlink href target


【解决方案1】:

我希望这会有所帮助。

<!DOCTYPE html>
<html>
   <head>
      <title>Page Title</title>
      <style></style>
   </head>
   <body>
      <a href="https://google.com/" trueblank="true" >Click Me</a>
      <script>
         var links = document.querySelectorAll("a");
         links.forEach(function(each) {
            each.onclick = function(ev) {
                if(this.getAttribute("trueblank") == "true") {
                    ev.preventDefault();
                    window.open(this.href);
                 }
             }
         });
      </script>
   </body>
</html>

【讨论】:

    【解决方案2】:

    按照下面的 JS 代码在当前窗口上打开一个新窗口,用户仍停留在第一页

      window.open("https://www.w3schools.com", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      • 1970-01-01
      • 2014-11-09
      • 1970-01-01
      相关资源
      最近更新 更多