2013-03-02 35 views
0

我有添加到YouTube頁面動態通過這個代碼的script.js文件:從動態添加腳本將消息發送給家長的Chrome擴展程序

var s = document.createElement('script'); 
    s.src = chrome.extension.getURL('Script.js'); 
    (document.head || document.documentElement).appendChild(s); 
    s.onload = function() { 
     s.parentNode.removeChild(s); 
    }; 

我有兩個問題:
1 - 我怎麼能將插入文件的消息發送到父項擴展。
2-我怎樣才能使從插入file..It的顯示錯誤消息的橫原點請求在控制檯

Origin http://www.youtube.com is not allowed by Access-Control-Allow-Origin. 

回答

0
  1. 使用postMessage或定製事件(example 1reference 2example 3)。
  2. 將清單permission添加到清單後,您可以從內容腳本發起跨站點請求。使用步驟1中的方法之一從網頁調用內容腳本。確保您只請求必要的權限(例如,如果您不需要訪問所有URL,則不需要*://*/*)並驗證所有輸入(以便惡意頁面不會濫用您的擴展名)。
相關問題