JavaScript Browser output
Last Update:2017-02-28
Source: Internet
Author: User
Javascript| Browser 26 Access Document object
1<script language= "JavaScript" >
2 var myurl = document. URL;
3 Window.alert (Myurl);
4</script>
27 Dynamic Output HTML
1<script language= "JavaScript" >
2 document.write ("<p>here ' s Some information about this document:</p>");
3 document.write ("<ul>");
4 document.write ("<li>referring Document:" + document.referrer + "</li>");
5 document.write ("<li>domain:" + document.domain + "</li>");
6 document.write ("<li>url:" + document. URL + "</li>");
7 document.write ("</ul>");
8</script>
28 Output Line Wrapping
1 Document.writeln ("<strong>a</strong>");
2 Document.writeln ("B");
29 Output Date
1<script language= "JavaScript" >
2 var thisdate = new Date ();
3 document.write (thisdate.tostring ());
4</script>
30 time zone for the specified date
1<script language= "JavaScript" >
2 var myoffset =-2;
3 var currentdate = new Date ();
4 var useroffset = Currentdate.gettimezoneoffset ()/60;
5 var timezonedifference = Useroffset-myoffset;
6 currentdate.sethours (currentdate.gethours () + timezonedifference);
7 document.write ("The time and date in the", Europe is: "+ currentdate.tolocalestring ());
8</script>
31 Set Date output format
1<script language= "JavaScript" >
2 var thisdate = new Date ();
3 var thistimestring = thisdate.gethours () + ":" + thisdate.getminutes ();
4 var thisdatestring = thisdate.getfullyear () + "/" + thisdate.getmonth () + "/" + thisdate.getdate ();
5 document.write (thistimestring + "on" + thisdatestring);
6</script>
32 Reading URL Parameters
1<script language= "JavaScript" >
2 var urlparts = document. Url.split ("?");
3 var parameterparts = Urlparts[1].split ("&");
4 for (i = 0; i < parameterparts.length; i++) {
5 var pairparts = parameterparts[i].split ("=");
6 var pairname = pairparts[0];
7 var pairvalue = pairparts[1];
8 document.write (Pairname + ":" +pairvalue);
9}
10</script> you still think HTML is stateless?
33 Open a new Document object
1<script language= "JavaScript" >
2 function NewDocument () {
3 Document.open ();
4 document.write ("<p>this is a New document.</p>");
5 Document.close ();
6}
7</script>
34 Page Jump
1<script language= "JavaScript" >
2 window.location = "http://www.velee.cn";
3</script>
35 Add Page Load Progress window
12 3 <script language= ' JavaScript ' >
4 var placeholder = window.open (' holder.html ', ' placeholder ', ' width=200,height=200 ');
5 </script>
6<title>the Main page</title>
78<body onload= ' placeholder.close () ' >
9<p>this is the main page</p>
10</body>
11