2011-07-14 10 views
0

HTMLページの中に貧しい人のFirebugを作成しようとしています。ターゲットページのどこかに配置された外部スクリプトを作成しました。 <body onload="monitor_init()">で初期化されます。また、部分的に不透明なテーブルを結果とともに絶対的に配置するためのスタイルシートも用意されています。ウィンドウ内の変数(またはすべて)の表示名、html/javascript

window[]のすべての値(値)を実行し、それを1つの列に表示し、typeof(window[i])を別の列に表示します。また、変数またはオブジェクトの名前を表示する別の列を持っていると思います。

function monitor_init() 
{ 
    var css = document.createElement("link"); 
    css.setAttribute("href","jsmonitor.css"); 
    css.setAttribute("rel","stylesheet"); 
    css.setAttribute("type","text/css"); 
    document.getElementsByTagName("head")[0].appendChild(css); 
    var temp = document.createElement("div"); 
    temp.setAttribute("id","monitor_box"); 
    var temp2 = document.createElement("table"); 
    temp2.setAttribute("id","monitor_output"); 
    temp.appendChild(temp2); 
    document.body.appendChild(temp); 
    monitor(); 
} 

var monitor_speed = 100; 

function monitor() 
{ 
    while(document.getElementById("monitor_output").childNodes.length > 0) 
    { 
     document.getElementById("monitor_output").removeChild(document.getElementById("monitor_output").lastChild); 
    } 
    for (i in window) 
    { 
     if (["function","undefined"].indexOf(typeof(window[i]))!=-1) 
     { 
      continue; 
     } 
     // This is where I tried to make a first column displaying the name, couldn't find anything that worked. 
     // Disregard the .name, that was just last-ditch stuff 
     //var temp = document.createElement("tr"); 
     //var temp2 = document.createElement("td"); 
     //temp2.appendChild(document.createTextNode(window[i].name)); 
     //temp.appendChild(temp2); 

     var temp = document.createElement("tr"); 
     var temp2 = document.createElement("td"); 
     temp2.appendChild(document.createTextNode(typeof(window[i]))); 
     temp.appendChild(temp2); 

     var temp2 = document.createElement("td"); 
     temp2.appendChild(document.createTextNode(window[i])); 
     temp.appendChild(temp2); 
     document.getElementById("monitor_output").appendChild(temp); 
    } 
    setTimeout("monitor()",monitor_speed); 
} 

typeofを使用することで、関数の値と未定義の値の表示をスキップすることができました。名前にアクセスできるようになるためには、JavaScriptの数字、文字列、配列オブジェクトなどではない履歴、場所、その他のもの、つまり他のスクリプトで作成したグローバル変数ページ上に - なぜあなたは放火魔のライトを使用することはできません

for (i in window) { 
    // at the point, i is a string containing the name of the property 
    // window[i] contains the value of that property 
    document.write('window.' + i + ' is ' + window[i] + '<br>'); 
} 

が、別のポスターなど

は尋ねた:

+1

Firegut Liteを使うことはできません。 http://getfirebug.com/firebuglite –

答えて

1

あなたは実際に特定の質問をしていませんが、「windowの各プロパティの名前を取得するにはどうすればよいですか?

既存のコードでは、for-inループを使用してさまざまなプロパティを実行しています。あなたが知っておくべきことは、あなたのインデックス変数が(現在の)プロパティの名前を保持することです:

for (i in window) { 
    alert("Property name: " + i); 
    alert("Property value: " + window[i]); 
} 
+0

ありがとうございます。私はどういうわけか、連想配列の各キーが含まれていることを忘れていました。 – user845573

1

ループ構築しますが、この情報を提供します使用していますか?

+0

このシンプルな機能に基づいて、より高度で具体的なトラッキングを試したかったのです。ありがとう。 – user845573

関連する問題