如何在 Chrome 扩展程序弹出窗口显示后触发事件?
我正在使用带有 Google Chrome 扩展弹出窗口的 jQuery。弹出页面使用 jQuery 的“document.ready”事件来触发对 Web 服务的请求。问题是弹出窗口在收到响应之前不会呈现,这使得它看起来没有响应。该页面的概要如下:
<html>
<head>
<script type="text/javascript" src="./plugin.js"></script>
<script type="text/javascript">
$(document).ready(function() {
plugin.init();
plugin.getData();
});
</script>
</head>
<body>...</body>
</html>
Chrome 呈现弹出窗口后,是否有一个事件可以用来触发“getData()”??我尝试过在体内处理 div 的可见性事件,但除了处理 document.ready 之外,我无法自动触发这些事件,这会导致相同的行为。
I am using jQuery with a Google Chrome extension popup. The pop-up page uses jQuery's 'document.ready' event to trigger a request to a web service. The problem is that the pop-up does not render until a response is received, which makes it seem unresponsive. Here's an outline of the page:
<html>
<head>
<script type="text/javascript" src="./plugin.js"></script>
<script type="text/javascript">
$(document).ready(function() {
plugin.init();
plugin.getData();
});
</script>
</head>
<body>...</body>
</html>
Is there an event I can use to trigger 'getData()' after Chrome renders the pop-up? I have tried monkeying with visibility events of divs within the body, but I haven't been able to trigger these events automatically other than by handling document.ready, which leads to the same behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
立即使用
setTimeout
:我已经在自己的扩展中完成了此操作,它应该可以解决问题。
Use
setTimeout
with no delay:I've done this in an extension of my own, and it should do the trick.
也许您可以与后台页面交互以异步获取数据:
后台:
Maybe you could interact with the background page to fetch data asynchronously:
Background: