2014-08-30 47 views
1

上搜索後注入一個腳本,我需要知道如何當我在谷歌搜索中鍵入注入一個腳本「開始擴展」如何谷歌網頁

我這樣做,但沒有奏效

if(location.origin === "https://www.google.com" && location.hash.indexOf("q=start+extension")!==-1) 
    (document.body || document.head).appendChild(script); 

回答

0

Google不會在搜索後重新加載頁面,因此您需要繼續測試,直到找到您要查找的頁面。我建議你用setTimeout做一個函數的遞歸調用

function inject() 
{ 
    if(location.origin === "https://www.google.com" && location.hash.indexOf("q=start+extension")!==-1) 
     (document.body || document.head).appendChild(script); 
    else 
     setTimeout(inject,2000); 
} 
inject();