javascript 常用代碼大全(十三)

來源:互聯網
上載者:User

 

// 17

//parse the search string,then return a object. 
//object info: 
//--property: 
//----result:a array contained a group of name/value item.the item is nested class. 
//--method: 
//----getNamedItem(name):find item by name.if not exists,return null; 
//----appendItem(name,value):apppend an item into result tail; 
//----removetItem(name):remove item which contained in result and named that name. 
//----toString():override Object.toString();return a regular query string. 
function parseQueryString(search){ 
var object=new Object(); 
object.getNamedItem=getNamedItem; 
object.appendItem=appendItem; 
object.removeItem=removeItem; 
object.toString=toString; 
object.result=new Array(); 
function parseItem(itemStr){ 
var arStr=itemStr.split("="); 
var obj=new Object(); 
obj.name=arStr[0]; 
obj.value=arStr[1]; 
obj.toString=toString; 
function toString(){ 
return obj.name+"="+obj.value; 

return obj; 

function appendItem(name,value){ 
var obj=parseItem(name+"="+value); 
object.result[object.result.length]=obj; 

function removeItem(name){ 
var j; 
for(j=0;j<object.result.length;j++){ 
if(object.result[j].name==name){ 
object.result.replice(j,1); 



function getNamedItem(name){ 
var j; 
for(j=0;j<object.result.length;j++){ 
if(object.result[j].name==name){ 
return object.result[j]; 


return null; 

function toString(){ 
var k; 
var str=""; 
for(k=0;k<object.result.length;k++){ 
str+=object.result[k].toString()+"&"; 

return str.substring(0,str.length-1); 

var items=search.split("&"); 
var i; 
for(i=0;i<items.length;i++){ 
object.result[i]=parseItem(items[i]); 

return object; 

關閉表單[無須修改][共1步] 
====1、將以下代碼加入HEML的<body></body>之間: 
<script language="JavaScript"> 
function shutwin(){ 
window.close(); 
return;} 
</script> 
<a href="javascript:shutwin();">關閉本視窗</a> 

檢測系統資訊 
<script language="JavaScript" type="text/javascript"> 
<!-- 
var newline = "/r/r" 
var now = new Date() 
var millinow=now.getTime()/1000 
var hours = now.getHours() 
var minutes = now.getMinutes() 
var seconds = now.getSeconds() 
var yourLocation="" 
now.setHours(now.getHours()+1) 
var min=60*now.getUTCHours()+now.getUTCMinutes() + now.getUTCSeconds()/60; 
var internetTime=(min/1.44) 
internetTime="Internet Time: @"+Math.floor(internetTime) 
var clock = "It’s exactly "+hours+":"+minutes+":"+seconds+" hours"  
var browser = "You are using " + navigator.appName +" "+navigator.appVersion 
yourLocation="You are probably living in "+yourLocation 
var winwidth= window.screen.width 
var winheight= window.screen.height 
var screenresolution= "Screen resolution: "+window.screen.width+" x "+window.screen.height 
var lastdoc = "You came from: "+document.referrer 
var expDays = 30; 
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000)); 
function Who(info){ 
var VisitorName = GetCookie(’VisitorName’) 
if (VisitorName == null) { 
VisitorName = "stranger"; 
SetCookie (’VisitorName’, VisitorName, exp); 

return VisitorName; 

function When(info){ 
// When 
var rightNow = new Date() 
var WWHTime = 0; 
WWHTime = GetCookie(’WWhenH’) 
WWHTime = WWHTime * 1 
var lastHereFormatting = new Date(WWHTime);  // Date-i-fy that number 
var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + 
lastHereFormatting.getDate() 
var lastHereInDateFormat = "" + lastHereFormatting;  // Gotta use substring functions 
var dayOfWeek = lastHereInDateFormat.substring(0,3) 
var dateMonth = lastHereInDateFormat.substring(4,11) 
var timeOfDay = lastHereInDateFormat.substring(11,16) 
var year = lastHereInDateFormat.substring(23,25) 
var WWHText = dayOfWeek + ", " + dateMonth + " at " + timeOfDay // display 
SetCookie ("WWhenH", rightNow.getTime(), exp) 
return WWHText; 

function Count(info){ 
var psj=0; 
// How many times 
var WWHCount = GetCookie(’WWHCount’) 
if (WWHCount == null) { 
WWHCount = 0; 

else{ 
WWHCount++; 

SetCookie (’WWHCount’, WWHCount, exp); 
return WWHCount; 

function set(){ 
VisitorName = prompt("Who are you?"); 
SetCookie (’VisitorName’, VisitorName, exp); 
SetCookie (’WWHCount’, 0, exp); 
SetCookie (’WWhenH’, 0, exp); 

function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1) 
endstr = document.cookie.length; 
return unescape(document.cookie.substring(offset, endstr)); 

function GetCookie (name) { 
var arg = name + "=";  
var alen = arg.length; 
var clen = document.cookie.length;  
var i = 0; 
while (i < clen) { 
var j = i + alen; 
if (document.cookie.substring(i, j) == arg) 
return getCookieVal (j); 
i = document.cookie.indexOf(" ", i) + 1; 
if (i == 0) break; 

return null; 

function SetCookie (name, value) { 
var argv = SetCookie.arguments; 
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null; 
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : ""); 

function DeleteCookie (name) { 
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
// This cookie is history 
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); 

var countvisits="You’ve been here " + Count() + " time(s). Last time was " + When() +"." 
if (navigator.javaEnabled()) { 
var javaenabled="Your browser is able to run java-applets"; 

else { 
var javaenabled="Your browser is not able to run java-applets"; 

function showAlert() { 
var later = new Date() 
var millilater=later.getTime()/1000 
var loadTime=(Math.floor((millilater-millinow)*100))/100 
var loadTimeResult= "It took you "+loadTime+" seconds to load this page" 
var babiesborn=Math.ceil(loadTime*4.18) 
var babiesbornresult="While this page was loading "+babiesborn+" babies have been born" 
if (babiesborn==1){babiesbornresult="While this page was loading "+babiesborn+" baby has been born"} 
alert 
(newline+newline+browser+newline+clock+newline+loadTimeResult+
newline+internetTime+newline+screenresolution+
newline+lastdoc+newline+countvisits+newline+javaenabled+newline+babiesbornresult+newline+newline) 

// --></script> 
<body onLoad="showAlert()"> 

密碼保護: 
將以下代碼加入HEML的<body></body>之間:

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.