【问题标题】:Get rid of second page that opens when executing an imacros script删除执行 imacros 脚本时打开的第二页
【发布时间】:2020-05-16 16:46:37
【问题描述】:

如何摆脱使用此 href 执行 imacros 脚本时打开的第二个页面

第一个选项卡是一个包含此标签的简单 html 页面:

<a target="blank" 
  href="javascript:window.open('imacros://run/?m=#current.js');">
    <button>Run macro</button>
</a>

点击此链接时,会打开第二个标签,其中包含图片中的内容以及我想要删除的内容。第三页包含我要执行的内容。

注意:我想保持第一页打开。

【问题讨论】:

  • 换个浏览器试试?
  • 我试过了,但我也希望它专门在cyberfox上工作

标签: javascript html css imacros


【解决方案1】:

试试这个。如果可行,则比在链接中使用 javascript href 和包装按钮更好的做法

您可以使用按钮代替链接

window.addEventListener("load",function() {
  document.querySelector("#imacro").addEventListener("click",function(e) {
    e.preventDefault();
    window.open(this.dataset.href)
  })
})
.button {
    display: block;
    width: 100px;
    height: 20px;
    padding: 10px;
    text-align: center;
    border-radius: 5px;
    border:1px solid black;
    font-weight: bold;
    text-decoration: none;
}
<a href="#" class="button" id="imacro"
  data-href="imacros://run/?m=#current.js">
   Run macro
</a>

【讨论】:

  • 感谢这真的很有效,而且更适合练习,我将 a 标签更改为按钮标签。
【解决方案2】:

无法测试,但我会尝试:

    <a
      href="#"
      onclick="javascript:window.open('imacros://run/?m=#current.js');return false;"
    >
      <button>Run macro</button>
    </a>

【讨论】:

  • 也许尝试最后一个版本,因为我在第一个答案中出错了。如果它仍然不起作用,则意味着 imacros://run/?m=#current.js 不能用作 URL,因为当替换为例如http://example.org/ 它打开了这个页面。不幸的是,我无法测试imacros URL。
猜你喜欢
  • 2015-06-10
  • 2015-07-04
  • 2022-06-24
  • 2020-10-25
  • 1970-01-01
  • 2022-07-08
  • 1970-01-01
  • 1970-01-01
  • 2019-08-17
相关资源
最近更新 更多