简体   繁体   English

如何在国外Ember应用程序上检测路由更改?

[英]How to detect a route change on foreign Ember application?

I'm trying to make a Chrome extension for Zendesk and it appears that their application is built with Ember. 我正在尝试为Zendesk开发Chrome扩展程序,看来他们的应用程序是使用Ember构建的。 I used $(document).ready, but that is only really firing if I refresh the pages... otherwise it doesn't fire at all. 我使用$(document).ready,但这只是在刷新页面时才真正触发...否则根本不会触发。 How can I listen for page changes in Zendesk for my Chrome extension? 如何在Zendesk中监听我的Chrome扩展程序的页面更改?

I looked around and only found answers that would help only if it was my own Ember app. 我环顾四周,只发现只有我自己的Ember应用程序才有帮助的答案。 Also, it isn't a hashchange. 另外,它也不是哈希变化。

It sounds like you want to implement a listener for the beforeunload event: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload 听起来您好像想为beforeunload事件实现一个侦听器: https : //developer.mozilla.org/en-US/docs/Web/Events/beforeunload

But rather than setting a confirmation message, implement whatever it is that you want to do when the navigation changes. 但是,与其设置确认消息,不如执行导航更改时想要执行的任何操作。 If you add a confirmation message it will popup a dialog that will ask you if you really want to navigate away, but it doesn't sound like thats what you want here. 如果添加确认消息,它将弹出一个对话框,询问您是否真的要离开,但这听起来并不是您想要的。 It sounds like you just want to monitor that a navigation event has occurred, but I could be mistaken. 听起来您只想监视一个导航事件已发生,但是我可能会误会。

Here are a few ideas: 这里有一些想法:

  • You could maybe hijack the history object methods. 您可能劫持了history对象方法。
  • Or if you have access to privileged chrome APIs, you could try using network.onNavigated . 或者,如果您可以访问特权的chrome API,则可以尝试使用network.onNavigated I don't know if it is invoked on history pushState though, better check. 我不知道是否在历史pushState上调用它,更好地检查一下。

You may also have a look at Ember inspector code , it provides a lot of insights on currently running ember app, including which route is currently active so you may find the tools to do what you need in there. 您还可以查看Ember检查器代码 ,它提供了有关当前正在运行的ember应用程序的很多见解, 包括当前处于活动状态的路由,因此您可以在其中找到所需的工具。

I think it works by injecting some code into the page, and then communicating with it through window messages. 我认为它可以通过向页面中注入一些代码,然后通过窗口消息与之通信来实现。 The injected code then does the requested analysis and sends back the result. 然后,注入的代码执行请求的分析并发回结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM