2014-08-30 68 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();