若y你想與頁面JavaScript交互,你將不得不在頁面中插入一個腳本。 (當然,除非你想使用本頁面建議的任何黑客技巧)。我已經爲我自己的腳本編寫了一個函數,我會在這裏發佈它,以防任何人想使用它。
/*
@description This function will insert the given code as a <script> or <style> block into a page.
@param The code to insert; supported types are: JavaScript Function, String (JavaScript), String (CSS).
@param2 Optional: The type of code that is inserted. If omitted, "js" is assumed. Possible values are 'js' or 'css'.
@return The HTML element that was inserted, or FALSE on failure
*/
function insert(z,t){
var j,f,x,c,i,n,d
d=document
c=d.createElement
i=d.head.appendChild
a=d.createTextNode
if(typeof z==='function') j=!0,f=!0;
if((t=='js'||!t)&&!f){j=!0,f=!1}
if(t=='css'&&!j){x=c('style');x.setAttribute('type','text/css')}
if(j){x=c('script');x.setAttribute('type','text/javascript')}
if(f) n=a('('+z+')()');else n=a(z)
x.appendChild(n)
if(x){return i(x)}else{return !1}
}
了幾個例子來闡明:
//Inserting a JavaScript function
var func=function(){
stopAds();
startFileDownload();
}
insert(func);
//Inserting JavaScript as a string
var strJS="prompt(\"Copy:\",someVariableAtThePage);";
insert(strJS);
//Or with an OPTIONAL 2nd parameter:
insert(strJS,'js');
//Inserting CSS
var strCSS=".ad{display:none !important} #downloadButton{display:block}";
insert(strCSS,'css');//Specifying 2nd parameter as "css" is required.
哦,如果變量是全球性的頁面,你應該能夠閱讀它的javascript – 2009-10-29 20:33:55