zoukankan      html  css  js  c++  java
  • 分享Chrome Extension(扩展程序/插件)开发的一些小经验

    1、不通过Chrome Web Store直接安装Chrome插件(Extension)

    我们之前开发网摘Chrome插件时,不需要通过Chrome Web Store,直接在网站上提供网摘插件的链接,用户点击就可以安装。后来,Chrome改为必须通过Web Store才能安装插件。

    我们找到了一个Hack的方法,在Chrome Extensions窗口,直接将下载至本地的网摘插件文件拖动到Extensions窗口即可。

    2、引用外部javascript文件的问题

    如果在Extenstion中引用了外部的js文件,会引发这样的错误:

    Refused to load the script 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js' because it violates the following Content Security Policy directive: "script-src 'self'".

    解决方法:在manifest.json中添加如下的代码(假设我们这里引用的是ajax.googleapis.com的js):

    "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",

    3、不支持inline javascript代码的问题

    从Chrome Extenstion V2开始,不允许执行任何inline javascript代码(也就是html内的任何js代码都不允许执行),比如下面的代码:

    <input type="submit" name="btn_submit" value="收藏" id="btn_submit" class="btn_submit" onclick="addwz()"/>

    onclick中的addwz()函数不允许执行,点击时会报错:

    Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' https://ajax.googleapis.com".

    解决方法:在内部引用的js文件中绑定事件,示例代码如下:

    $('#btn_submit').click(function () {
        addwz();
    });
  • 相关阅读:
    最大熵原理
    python单引号、双引号和三双引号的区别
    python的字典
    hadoop jar xxxx.jar 执行的流程
    java 正则表达式
    secureCRT中vim个性化设置
    python关系运算符的全称
    C# 分割字符
    委托(delegate)
    在C#中,委托(delegate)
  • 原文地址:https://www.cnblogs.com/dudu/p/chrome_extension.html
Copyright © 2011-2022 走看看