JavaScript DHTML/Javascript Objects/document
Содержание
- 1 Active Element
- 2 Create a Comment
- 3 Document compatMode
- 4 Document design Mode
- 5 Document doctype
- 6 Document Domain
- 7 Document Link color
- 8 Document parentWindow
- 9 Document referrer
- 10 Document title Example
- 11 Document "URLUnencoded" Example
- 12 Execute Command
- 13 "expando" Example
- 14 Expose the prperties of Objects
- 15 Print page out
- 16 "URL" Example
- 17 Use document.links collection
- 18 "write()" Example
- 19 "writeln()" Example
Active Element
<html>
<body onLoad="myButton.focus();">
<input type="Button" id="myButton" value="Element 1" onClick="function1();">
<script language="JavaScript">
function function1() {
var m = document.activeElement.value;
alert("The active element is "+m);
}
</script>
</body>
</html>
Create a Comment
<html>
<body>
Body content.
<script language="JavaScript">
document.createComment("This is the comment text");
</script>
</body>
</html>
Document compatMode
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3c.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript">
function function1() {
alert(document.rupatMode);
}
</script>
</head>
<body>
<button onclick ="function1();">CompatMode</button>
</body>
</html>
Document design Mode
<html>
<body>
<button onclick="alert(document.designMode);">Design Mode Status</button>
</body>
</html>
Document doctype
<!doctype html public "-//w3c//dtd html 4.0//en-us">
<html>
<head>
<script language="JavaScript">
function function1() {
alert(document.doctype);
}
</script>
</head>
<body>
<input type="button" onClick="function1();" value="doctype">
</body>
</html>
Document Domain
<html>
<body>
<script language="JavaScript">
function function1() {
var m = document.domain;
if (m) {
alert(m);
} else {
alert("No security domain");
}
}
</script>
<input type="button" onClick="function1();" value="Domain Name">
</body>
</html>
Document Link color
<html>
<body onload="document.body.link = "blue";">
<script language="JavaScript">
function function1() {
document.linkColor = "green";
}
</script>
<a href="http://www.wbex.ru">wbex.ru Web page</a>
<input type="button" value="Change the link color to green" onClick="function1();">
</body>
</html>
Document parentWindow
<html>
<body>
<script language="JavaScript">
function function1() {
alert(document.parentWindow.frames.length);
}
</script>
<input type="button"
value="How many frames in this window?"
onclick="function1();">
</body>
</html>
Document referrer
<html>
<body>
<script language="JavaScript">
function function1() {
var m = document.referrer;
alert(m);
}
</script>
<input type="button" value="Get referrer" onclick="function1();">
</body>
</html>
Document title Example
<html>
<head>
<title>properties_title</title>
<script language="JavaScript">
function function1() {
document.title = "This is the new title ";
}
function function2() {
var n = document.title; alert(n);
}
</script></head>
<body>
<button onclick="function1();">Click here to change the title of this page</button>
<button onclick="function2();">Click here to display the title of this page</button>
</body></html>
Document "URLUnencoded" Example
<html>
<body>
<button onclick="alert(document.URLUnencoded);">URL Unencoded</button>
</body>
</html>
Execute Command
<html>
<body>
<script language="JavaScript">
function function1() {
document.execCommand("Refresh", "false", "false");
}
</script>
<button onclick="function1();">Refresh page</button>
</body>
</html>
"expando" Example
<html>
<body>
<p id="myElement">Sample text, try to select part of it</p>
<script language="JavaScript">
function function1() {
myElement.setAttribute("unselectable", "off", 0);
document.expando = true;
}
function function2() {
myElement.setAttribute("unselectable", "on", 0);
document.expando = true;
}
</script>
<button onclick="function2();">Unselectable</button>
<button onclick="function1();">Selectable</button>
</body>
</html>
Expose the prperties of Objects
<html>
<head>
<title>Expose the Objects</title>
</head>
<body>
<script type="text/javascript">
for (docprop in document) {
document.writeln(docprop + "=");
eval ("document.writeln(document." + docprop + ")");
document.writeln("<br />");
}
</script>
</body>
</html>
Print page out
<html>
<head>
<title>Print()</title>
</head>
<body>
<form>
<input type="button" name="printWhole" value="Print Entire Frameset"
onclick="parent.print()" />
<p>
</body>
</html>
"URL" Example
<html>
<body>
<button onclick="alert(document.URL);">URL</button>
</body>
</html>
Use document.links collection
<html>
<head>
<title>Reference</title>
</head>
<body>
<a href="http://www.wbex.ru">wbex.ru</a>
<p>
<script type="text/javascript">
for (var i = 0; i < document.links.length; i++) {
var link = document.links[i];
document.writeln(link.title + " : " + link.href + "<br />");
}
</script>
</p>
</body>
</html>
"write()" Example
<html>
<body>
<script language="JavaScript">
function function1() {
var m = "<p>This is a sample text. First paragraph.</p>";
m += "<p>This is the second paragraph.</p>"
document.write(m);
}
</script>
<input type="button" value="Add some HTML content to this page" onClick="function1();">
</body>
</html>
"writeln()" Example
<html>
<body>
<script language="JavaScript">
function function1() {
var m = "<p">This is a sample text. First paragraph.</p>";
m += "<p>This is the second paragraph.</p>"
document.writeln(m);
}
</script>
<input type="button" value="Add some HTML content to this page" onClick="function1();">
</body>
</html>