【问题标题】:How to redirect to custom web page after seeing if a string is present in web page查看网页中是否存在字符串后如何重定向到自定义网页
【发布时间】:2021-09-02 12:17:03
【问题描述】:

检查网页中是否存在一组字符串后如何重定向到链接

例如: 你好世界出现在网页中 脚本检查“hello world”是否存在,如果存在则重定向到链接

【问题讨论】:

    标签: javascript html css node.js dynamic


    【解决方案1】:

    您可以遍历页面上的每个元素并测试搜索字符串。

    注意将其放在页面的<head> 部分,而不是<body>

    document.body.querySelectorAll('*').forEach(e => {
      if (e.innerText.includes("hello world")) window.location = "http://google.com";
    })

    您可以遍历页面上的每个元素并查看搜索字符串是否存在...

    document.body.querySelectorAll('*').forEach(e => {
       if (e.innerText.includes("hello world")) window.location = "http://google.com";
    })
    

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 2012-12-07
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 2011-10-01
      相关资源
      最近更新 更多