我使用带有Google Chrome扩展程序弹出框的jQuery。弹出页面使用jQuery的'document.ready'事件来触发对Web服务的请求。问题在于弹出窗口在接收到响应之前不会呈现,这使得它看起来没有反应。以下是该页面的大纲:
< html> < head> < script type =text / javascriptsrc =./ plugin.js>< / script> < script type =text / javascript> $(document).ready(function(){ plugin.init(); plugin.getData(); }); < / script> < / head> < body> ...< / body> < / html>是否有一个事件可以在 Chrome呈现弹出窗口?我曾尝试用身体内的div的可见性事件来瞎搞,但除了处理document.ready,我还没有能够自动触发这些事件,这导致了相同的行为。
<$ p $ p> < HTML> < head> < script type =text / javascriptsrc =./ plugin.js>< / script> < script type =text / javascript> $(document).ready(function(){ plugin.init(); setTimeout(plugin.getData); }); < / script> < / head> < body> ...< / body> < / html>我已经在自己的扩展中完成了这个工作, p>
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.
解决方案Use setTimeout with no delay:
<html> <head> <script type="text/javascript" src="./plugin.js"></script> <script type="text/javascript"> $(document).ready(function() { plugin.init(); setTimeout(plugin.getData); }); </script> </head> <body>...</body> </html>I've done this in an extension of my own, and it should do the trick.
更多推荐
显示Chrome扩展程序弹出窗口后如何触发事件?
发布评论