JavaScript DHTML/Javascript Objects/document

Материал из Web эксперт
Перейти к: навигация, поиск

Active Element

   <source lang="html4strict">

   

<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>


 </source>
   
  


Create a Comment

   <source lang="html4strict">

   

<html> <body> Body content. <script language="JavaScript">

   document.createComment("This is the comment text");

</script> </body> </html>


 </source>
   
  


Document compatMode

   <source lang="html4strict">

   

<!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>


 </source>
   
  


Document design Mode

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(document.designMode);">Design Mode Status</button> </body> </html>


 </source>
   
  


Document doctype

   <source lang="html4strict">

   

<!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>


 </source>
   
  


Document Domain

   <source lang="html4strict">

   

<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>


 </source>
   
  


Document Link color

   <source lang="html4strict">

   

<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>


 </source>
   
  


Document parentWindow

   <source lang="html4strict">

   

<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>


 </source>
   
  


Document referrer

   <source lang="html4strict">

   

<html> <body> <script language="JavaScript"> function function1() {

   var m = document.referrer; 
   alert(m);

} </script> <input type="button" value="Get referrer" onclick="function1();"> </body> </html>


 </source>
   
  


Document title Example

   <source lang="html4strict">

   

<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>


 </source>
   
  


Document "URLUnencoded" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(document.URLUnencoded);">URL Unencoded</button> </body> </html>


 </source>
   
  


Execute Command

   <source lang="html4strict">

   

<html> <body> <script language="JavaScript"> function function1() {

   document.execCommand("Refresh", "false", "false");

} </script> <button onclick="function1();">Refresh page</button> </body> </html>


 </source>
   
  


"expando" Example

   <source lang="html4strict">

   

<html> <body>

Sample text, try to select part of it

<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>


 </source>
   
  


Expose the prperties of Objects

   <source lang="html4strict">
  

<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("
");

} </script> </body> </html>


 </source>
   
  


Print page out

   <source lang="html4strict">
  

<html> <head> <title>Print()</title> </head> <body> <form> <input type="button" name="printWhole" value="Print Entire Frameset" onclick="parent.print()" />

</body> </html> </source>

"URL" Example

   <source lang="html4strict">

   

<html> <body> <button onclick="alert(document.URL);">URL</button> </body> </html>


 </source>
   
  


Use document.links collection

   <source lang="html4strict">
  

<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 + "
");

} </script>

</body> </html>


 </source>
   
  


"write()" Example

   <source lang="html4strict">

   

<html> <body> <script language="JavaScript"> function function1() {

var m = "

This is a sample text. First paragraph.

"; m += "

This is the second paragraph.

"
   document.write(m); 

} </script> <input type="button" value="Add some HTML content to this page" onClick="function1();"> </body> </html>


 </source>
   
  


"writeln()" Example

   <source lang="html4strict">

   

<html> <body> <script language="JavaScript"> function function1() {

   var m = "<p">This is a sample text. First paragraph.</p>";
m += "

This is the second paragraph.

"
   document.writeln(m); 

} </script> <input type="button" value="Add some HTML content to this page" onClick="function1();"> </body> </html>


 </source>