document.body.scrollWidth document.body.scrollHeight
document.width document.height
// Quirks Mode (*1) document.body.clientWidth document.body.clientHeight // Standard Mode document.documentElement.clientWidth document.documentElement.clientHeight(*1) ブラウザのレンダリングモード(Quirks/Standards)により返る値が異なるので注意が必要。Standards Modeで動作している場合、document.body.clientHeightでは、ドキュメントの高さが返される。このため、document.documentElement.clientHeightから取得する必要がある。
window.innerWidth window.innerHeight
ウィンドウ左上のドキュメント内における座標(つまりウィンドウのスクロール量)の取得の仕方。
// Quirks Modeの場合 (*1) document.body.scrollLeft document.body.scrollTop // Standard Modeの場合 (*2) document.documentElement.scrollLeft document.documentElement.scrollTop
window.pageXOffset window.pageYOffset
frames['xxxx'].window frames['xxxx'].document xxxxはiframeのid。 以下でも取得できる。 (IEにはcontentDocumentプロパティは存在しないので注意) document.getElementById(id).contentWindow document.getElementById(id).contentWindow.document
document.getElementById(id).contentWindow; document.getElementById(id).contentDocument;
element.onmousedown = function () {window.event;}
NN6,FireFox
element.onmousedown = function (event) {event;}
|
プロパティ |
説明 |
|
|---|---|---|
| IE |
NN6,FireFox |
|
|
button |
which |
押されたマウスボタン。 1:左、2:中、3:右 |
|
---- |
pageX,pageY |
ドキュメント座標系でのマウス座標 |
|
clientX,clientY |
←同じ | クライアントウィンドウ内のマウス座標 |
| screenX,screenY |
←同じ |
スクリーン内のマウス座標 |
|
srcElement |
target |
イベント発生元のオブジェクト |
var table = document.createElement("table");
var tbody = document.createElement("tbody");
table.appendChild(tbody);
for(var i = 0 ; i < rows ; i++) {
var tr = document.createElement("tr");
for(var j = 0 ; j < cols ; j++) {
var td = document.createElement("td");
td.innerHTML = "cell";
tr.appendChild(td);
}
tbody.appendChild(tr);
}
IEの場合でもinnerHTMLに直接HTMLを書き込む場合は、<tbody>を入れなくても動作する。ただし、tbodyは自動的に挿入されてしまう。innerHTMLでテーブルを作ってからDOM操作をする場合は、<tbody>があっても動作するようにしておかないといけないので注意が必要。Mozilla系では<tbody>が勝手に挿入されることはない。
var div = document.createElement("div");
div.innerHTML =
"<table><tr><td>cell</td><td>cell</td></tr></table>";
document.createStyleSheet("sample.css");
var link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("href", "sample.css");
link.setAttribute("type", "text/css");
document.getElementsByTagName('head')[0].appendChild(link);
IE6: frames[id].document; Mozilla系: document.getElementById(id).contentDocument idは<iframe>のid属性値FireFox1.5では<iframe>にsrc属性値が設定されていないと、スタイルシートの追加はできなかった。(LINKエレメントは追加できるのだがstyleSheetsプロパティにエントリが追加されなかった)
document.getElementById(id).className = "xxxx";
document.getElementById(id).setAttribute("class", "xxxx");
document.createElement("form").encoding = "multipart/form-data"
document.createElement("form").enctype = "multipart/form-data"
element.style.styleFloat = "left"
element.style.cssFloat = "left"