Chrome扩展程序不会从弹出文件加载我的JavaScript [英] Chrome Extension won't load my JavaScript from the popup file

查看:127
本文介绍了Chrome扩展程序不会从弹出文件加载我的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为论坛构建Chrome扩展程序,但问题在于我的popup.html的JavaScript不会执行任何操作。我在顶部添加了alert(popup.js running ...),它确实出现了,但弹出窗口根本不显示。这是一个问题,因为JavaScript将被要求用于弹出页面。我有点失落,所以我假设我只是错过了阻止我的JavaScript运行的东西。我听说AdBlock扩展会阻止它运行,但我删除了它,但它仍然无法工作。任何人都可以看到问题?



manifest.json

  {
name:Riggy,
short_name:Riggy,
description:用Riggy创建您自己的Roblox论坛签名!,
version: 0.0.1,
manifest_version:2,
browser_action:{
default_popup:popup / popup.html
},
权限:[
存储
],
content_scripts:[
{
匹配:[http://www.roblox。 com / *],
js:[scripts / jquery.js,scripts / content.js]
}
]
}



preopup c><!DOCTYPE html>
< html>
< head>
< link rel =stylesheettype =text / csshref =popup.css/>
< script type =text / javascriptsrc =scripts / jquery.js>< / script>
< / head>
< body>
< span class =title> Riggy< / span>< br />
< span>签名:< / span>< input name =siggyid =siggyvalue =Riggy is greatness! />
< span id =output> [输出]< / span>
< script type =text / javascriptsrc =popup.js>< / script>
< / body>
< / html>



popup.js

  alert(popup.js running); 
$(document).on(ready,function(){
var siggy = $(#siggy);
var output = $(#output);

函数消息(文本){
output.html(文本);
}

siggy.change(函数(){
chrome .storage.sync.set({siggy:siggy.val()},function(){
message(Saved signature。);
});
});

消息(Riggy已准备好!);
});


解决方案

,我相信在将它添加到清单文件后它已被修复。



manifest.json

 content_security_policy:script-src'self''unsafe-eval'; object-src'self'

更多信息: http://developer.chrome.com /extensions/contentSecurityPolicy.html


I'm working on building a Chrome extension for a forum, but the problem is the JavaScript for my popup.html won't do anything. I added alert("popup.js running...") at the top and it does come up but then my popup doesn't display at all. This is a problem because JavaScript is going to be required for the popup page. I'm kind of lost, so I'm assuming I'm just missing something that is preventing my JavaScript from running. I heard the AdBlock extension would prevent it from running but I removed that and it still didn't work. Anyone see a problem?

manifest.json

{
    "name": "Riggy",
    "short_name": "Riggy",
    "description": "Create your own Roblox Forum signature with Riggy!",
    "version": "0.0.1",
    "manifest_version": 2,
    "browser_action": {
        "default_popup": "popup/popup.html"
    },
    "permissions": [
        "storage"
    ],
    "content_scripts": [
        {
            "matches": ["http://www.roblox.com/*"],
            "js": ["scripts/jquery.js", "scripts/content.js"]
        }
    ]
}

popup.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="popup.css" />
        <script type="text/javascript" src="scripts/jquery.js"></script>
    </head>
    <body>
        <span class="title">Riggy</span><br />
        <span>Signature: </span><input name="siggy" id="siggy" value="Riggy is greatness!" />
        <span id="output">[output]</span>
        <script type="text/javascript" src="popup.js"></script>
    </body>
</html>

popup.js

alert("popup.js running");
$(document).on("ready", function() {
    var siggy = $("#siggy");
    var output = $("#output");

    function message(text) {
        output.html(text);
    }

    siggy.change(function() {
        chrome.storage.sync.set({"siggy": siggy.val()}, function() {
            message("Saved signature.");
        });
    });

    message("Riggy is ready!");
});

解决方案

I had the same exact problem with an extension of mine, I believe it was fixed after I added this to the manifest file.

manifest.json

"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"

More info here: http://developer.chrome.com/extensions/contentSecurityPolicy.html.

这篇关于Chrome扩展程序不会从弹出文件加载我的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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