【问题标题】:How to interact with elements of the tab opened with GM_openInTab如何与使用 GM_openInTab 打开的选项卡的元素进行交互
【发布时间】:2023-04-01 19:09:01
【问题描述】:

我正在我的 tampermonkey 脚本中使用 GM_openInTab 打开一个新标签,但我无法使用我的代码与这个新标签的元素进行交互。

我只是想在新打开的选项卡中单击一个按钮,然后立即关闭它。

提前致谢!

【问题讨论】:

    标签: javascript greasemonkey tampermonkey greasemonkey-4 webgrease


    【解决方案1】:

    您还必须在打开的新标签页的 URL 上运行脚本(在顶部添加一个额外的 @include),您可以在脚本的开头进行区分,如下所示:

    if (location.href == oldurl){
      //open new tab
    } else if (location.href == newurl){
      //click button, close
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 2019-07-18
      • 2021-06-29
      • 1970-01-01
      • 2021-08-19
      • 2015-06-21
      • 1970-01-01
      相关资源
      最近更新 更多