绕过“无弹出”如果我想在点击扩展时运行javascript [英] Bypassing the "no popup" if I want a javascript to run when extension clicked

查看:179
本文介绍了绕过“无弹出”如果我想在点击扩展时运行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Chrome扩展,只要按下弹出窗口就可以触发。目前我只有在我从manifest.json中删除popup.html时才能做到这一点,因为它有一个限制。然而,我需要popup.html



我该如何获得这两者?



同样的东西,在popup.html中,在popup.js(在popup.html中正确链接),没有任何东西。



总之,如果我把这在background.js中:

  chrome.browserAction.onClicked.addListener(function(info,tab){
speakMe();
});

有用。 然而,意味着清单中没有popup.html。所以,我自然会尝试这样做:

 < script> 
chrome.browserAction.onClicked.addListener(function(info,tab){
speakMe();
});
< / script>

位于popup.html中。它不起作用。按下图标会正常显示弹出窗口,但没有任何反应。



我试着将它放在popup.js中,但仍然没有任何结果。我在做什么错了?

解决方案

在你的popup.js中添加一个onload监听器:

  onload = function(){console.log(I loaded!); }; 

在该函数中,当弹出窗口出现时,您可以做有趣的事情。如果您想要获得更多幻想,您可能会遇到 https://code.google.com/p/chromium/issues/detail?id=31262



顺便说一下,您还没有告诉我们什么它不工作意味着(哪一行失败?是否有控制台错误消息?),所以很难确定这个答案(或任何)对你有帮助。请参阅 https://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist 的步骤,以确保给出的答案是您的问题的答案。


I have a chrome extension which I want to fire whenever I press the popup. Currently I can do this only if I remove the popup.html from manifest.json, since there's a restriction on that. However, I need the popup.html

How do I get both?

I have tried placing the exact same thing everywhere, in the popup.html, in the popup.js (which is linked correctly in the popup.html) and nothing.

In short, if I place this in the background.js:

chrome.browserAction.onClicked.addListener(function(info, tab) {
    speakMe();
    });

It works.

However, that implies no popup.html in the manifest. So, naturally, I try placing this:

    <script>
    chrome.browserAction.onClicked.addListener(function(info, tab) {
  speakMe();
});
    </script>

in the popup.html. It doesn't work. Pressing the icon displays the popup normally, but nothing happens.

I tried placing it in the popup.js too, still nothing. What am I doing wrong?

解决方案

Add an onload listener into your popup.js:

onload = function() { console.log("I loaded!"); };

In that function you can do interesting things when the popup appears. If you want to get more fancy than that, you might run into issues described in https://code.google.com/p/chromium/issues/detail?id=31262.

By the way, you haven't told us what "It doesn't work" means (which line fails? Are there console error messages?), so it's hard to be sure that this answer (or any) is helpful to you. See https://meta.stackexchange.com/questions/156810/stack-overflow-question-checklist for steps to follow to make sure that answers given are answers to your question.

这篇关于绕过“无弹出”如果我想在点击扩展时运行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆