javascript - 无法从弹出窗口运行 JavaScript 行

标签 javascript jquery html google-chrome-extension

当我尝试打开以下页面作为弹出窗口时,我遇到了以下消息:

Refused to load the script 'http://allinternetfinance.com/LetMeKnow/jquery-1.11.2.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'

index.html:4 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'". Either the 'unsafe-inline' keyword, a hash ('sha256-anuyZ9J88P7xGyiuMhMfVwpc613qkiD1ZB3UusOLD6A='), or a nonce ('nonce-...') is required to enable inline execution."

html 是:

<html>
<head>
    <script src="http://allinternetfinance.com/LetMeKnow/jquery-1.11.2.js";></script>
    <script>
    $( document ).ready(function() {
        window.location.replace("http://localhost:8080/MembershipApp/index.html");
    });
    </script>
</head>

<body>
</body>

我得到的只是白色的小方 block ,而不是我试图将其重定向到的页面。

最佳答案

您首先需要做两件事:

  • 下载 Jquery 并从扩展文件夹中加载它,或者根本不使用它。
  • 将脚本标记的内容移至 .js 文件并引用它。

https://developer.chrome.com/extensions/contentSecurityPolicy

此外,弹出窗口似乎必须包含扩展文件,而是使用

chrome.tabs.create({ url: "http://localhost:8080/MembershipApp/index.html"})

关于javascript - 无法从弹出窗口运行 JavaScript 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30710239/

相关文章:

javascript - 是否可以允许用户仅选择一个复选框(bootstrap checkbox-x)?

javascript - Angular Js 初学者 Ajax 调用

html - IE6 和 IE7 绝对定位的 div 在多个相对 div 之上

PHP 意外包含打印

javascript - 如何计算乘客总数

javascript - 当显示器屏幕分辨率不是方形时,如何绘制圆形而不是椭圆形?

jquery - 在jquery datepicker上设置mindate (dd.mm.yyyy)

javascript - jquery css 显示属性设置为 '' “它是有效用法吗?

css - DataTables Firefox 空 <th>&nbsp</th> css 边框错误

javascript - 如何在 MS CRM 2013 中创建内联对话框