假设我的浏览器中加载了一个网络聊天应用程序(外部)。与所有聊天一样,您会收到有关某些事件的通知,例如新消息。 聊天会更新聊天的 DOM 以反射(reflect)这一点。
我想要实现的是通过搜索此 DOM 以查找特定事件(即 newmessage= 1),我可以使用该信息在我拥有的网页上触发警报(DOM 更新)。
我看过使用脚本获取/加载内容/url 的示例,但我猜这会获取页面的新实例,但这不是我需要的。
简单来说。我有一个 Web 应用程序,它可以显示(在单独的 div 中)一个包含另一个不是我的聊天的 iframe。人们可以将 View 切换到我的聊天和其他人。我想在查看自己的聊天时收到来自其他聊天的新消息提醒。
我希望我问的有点清楚。 ;-)
我正在使用 PHP、Javascript/Jquery 进行我自己的聊天。
最佳答案
这会违反 same origin policy :
In computing, the same-origin policy is an important concept in the web application security model. The policy permits scripts running on pages originating from the same site – a combination of scheme, hostname, and port number1 – to access each other's DOM with no specific restrictions, but prevents access to DOM on different sites.
关于javascript - 通过 DOM 加载页面搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24594280/