Chrome扩展内联脚本拒绝错误

时间:2015-11-20 10:00:54

标签: javascript jquery html ajax google-chrome-extension

我正在创建一个chrome扩展程序,当用户单击页面上的按钮时,它会启动一个新的HTML页面。在HTML页面中我有一些内联脚本,但是当我尝试执行它时,显示以下错误:

  

拒绝执行内联脚本,因为它违反了以下内容   内容安全策略指令:“script-src'self'blob:   filesystem:chrome-extension-resource:“。'unsafe-inline'   关键字,哈希('sha256-Yf ********* hI =')或nonce('nonce -...')是   启用内联执行所必需的。

这是我的HTML页面:

 <!DOCTYPE html>
 <html>   
 <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'">
  <head> 
    <script> function closeWindow(){ alert( a has been updated ) ;  window.close();}
    </script> 
    <style> 
      #leadinformation { text-align: left; font: 12px; position :absolute; padding:20px 20px 20px 20px;} 
      button { position: relative; top: 30%;  font-family: Arial;font-weight: bold; font-size: 13px; color: #ffffff; padding: 5px 5px 5px 5px;background-image: webkit-linear-gradient(top, #287bbc 0%,#23639a 100%);background-color: #287bbc; border-width: 1px; border-style: solid; border-radius: 3px 3px 3px 3px; boder-color: #1b5480; width: 160px; height: 35px;} 
      #titleParagraph {font-weight:bold; font-size:20px;} 
    </style>  
  </head> 
   <body> 


    <form> 
     <div id="leadinformation"> 
      <p id="titleParagraph">You are about to create a new Lead:</p> 
        First Name.....   <input type="text" id="firstname" value= window.openerfirstname >   <br> 
        Last Name.....   <input type="text" id="lastname" value= lastname >   <br> 
        Title:...............   <input type="text" id="position" value= positions[0] >   <br> 
        Company:......   <input type="text" id="company" value= companies[0] >   <br> 
        Email:............   <input type="text" id="email" value= email >   <br> 
        Phone:...........   <input type="text"  id="phonenumber" value= phonenumber >   <br>  <br> 
      <div> 

        <button id="Accept" onClick=closeWindow() >Accept</button> 
        <button id="Close" onClick=closeWindow() >Close</button> 
       </form> 
     </div> 
    </body> 
   </html>  

这是在我的content.js文件中:

var url = chrome.extension.getURL("window-child.html");
myWindow =window.open(url,"_blank", "width=400,height=300,0,status=0");
 myWindow.addEventListener('load', function(){
myWindow.document.getElementById('Accept').onclick=addToLeads;
myWindow.document.getElementById('Close').onclick=Close;
});

在我的清单中:

 "permissions": [
    "tabs", "<all_urls>","storage" , "alarms", "*://*/window-child.html?"

我有以下问题:

1)我在上面展示的错误不允许我在HTML页面内执行内联脚本

2)我想调用函数Accept()Close(),它们位于content.js中,但在按下按钮时在HTML页面中触发

3)我想使用用户在内容脚本中的HTML页面中输入的输入值(可以使用本地存储吗?)

任何帮助都将受到高度赞赏!谢谢!

0 个答案:

没有答案
相关问题