Custom Search



Nơi bạn đến là nơi tôi bắt đầu, nơi tôi qua sẽ là nơi bạn đến...

Wednesday, September 19, 2012

TỔNG HỢP CÁC CODE JAVASCRIPT HAY

1. Cấm click chuột phải:


Code:
<SCRIPT language=JavaScript1.1> function right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { alert('Chuc Mot Ngay Vui ve - Gui Wedsite Cho Ban Be Cua Minh Nha !'); return false; } return true; } document.onmousedown=right; if (document.layers) window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right; </SCRIPT> 

2. Không cho phủ khối văn bản để copy:

<script type="text/javascript"> 
/*********************************************** ********** Disable Text Selection script *************** ***********************************************/ function disableSelection(target){ if (typeof target.onselectstart!="undefined") //IE route target.onselectstart=function(){return false} else if (typeof target.style.MozUserSelect!="undefined") //Firefox route target.style.MozUserSelect="none" else //All other route (ie: Opera) target.onmousedown=function(){return false} target.style.cursor = "default" } //Sample usages //disableSelection(document.body) //Disable text selection on entire body //disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv" </script> 

3. Code chống click chuột phải và nếu người dùng cố tình click nữa thì web sẽ tự động giựt màn hình cảnh báo:

<SCRIPT language=JavaScript> document.onmousedown=click var times=0 var times2=10 function click() { if ((event.button==2) || (event.button==3)) { if (times>=1) { earthquake() } alert("Ban Ko Dc Click Chuot Phai"); times++ } } function earthquake() { alert("Ban Ko Dc Click Chuot Phai"); window.moveTo(0, 0) window.moveTo(1, 1) window.moveTo(2, 2) window.moveTo(3, 3) window.moveTo(4, 4) window.moveTo(5, 5) window.moveTo(6, 6) window.moveTo(7, 7) window.moveTo(8, 8) window.moveTo(9, 9) window.moveTo(10, 10) window.moveTo(9, 9) window.moveTo(8, 8) window.moveTo(7, 7) window.moveTo(6, 6) window.moveTo(5, 5) window.moveTo(4, 4) window.moveTo(3, 3) window.moveTo(2, 2) window.moveTo(1, 1) alert("Giat Nhu Fiml Nha??!") tremmors() } function tremmors() { window.moveTo(0, 0) window.moveTo(1, 1) window.moveTo(2, 2) window.moveTo(3, 3) window.moveTo(4, 4) window.moveTo(5, 5) window.moveTo(6, 6) window.moveTo(7, 7) window.moveTo(8, 8) window.moveTo(9, 9) window.moveTo(10, 10) window.moveTo(11, 11) window.moveTo(12, 12) window.moveTo(9, 9) window.moveTo(8, 8) window.moveTo(7, 7) window.moveTo(6, 6) window.moveTo(5, 5) window.moveTo(4, 4) window.moveTo(3, 3) window.moveTo(2, 2) window.moveTo(1, 1) tremmors() } </SCRIPT> 

4. Vòng tròn lấp lánh bao quanh chuột:

<script language="JavaScript"> <!-- Mouse Attack by Kurt Grigg - http://www.btinternet.com/~kurt.grigg/javascript var num=10;//Number of dots! var vel=20;//Speed! var col=new Array('#0080ff','#ffffff','#0000ff','#44ccff');//Dot colours, min 2! var stopafter=60; //Stop and clear after x secondS! //Nothing needs altering past here.................... var MAy=0; var MAx=0; var py=0; var px=0; var angle=0; var distance=0; var rep; var ry=0; var rx=0; var tmr=null; var n4=(document.layers); var n6=(document.getElementById&&!document.all); var ie=(document.all); var o6=(navigator.appName.indexOf("Opera") != -1)?true:false; var _d=(n4||ie)?'document.':'document.getElementById(" '; var _a=(n4||n6)?'':'all.'; var _r=(n6)?'")':''; var _s=(n4)?'':'.style'; var v=(n4)?"show":"visible"; var put=false; stopafter*=1000; if (n4||n6){ window.captureEvents(Event.MOUSEMOVE); function mouse1(e){ if (put) return false; MAy = e.pageY-window.pageYOffset; MAx = e.pageX; } if (n4) window.onMouseMove=mouse1; else document.onmousemove=mouse1; } if (ie||o6){ function mouse2(){ if (put) return false; MAy = (ie)?event.clientY:event.clientY-window.pageYOffset; MAx = event.clientX; } document.onmousemove=mouse2; } if (n4){ for (inc=0; inc < num; inc++) document.write('<layer name=dots'+inc+' top=0 left=0 width='+inc/3+' height='+inc/3+' bgcolor=#ffffff></layer>'); } else{ if (ie&&!o6){ document.write("<div id='outer' style='position:absolute;top:0px;left:0px'>"); document.write("<div style='position:relative'>"); } for (inc=0; inc < num; inc++) document.write('<div id="dots'+inc+'" style="position:absolute;top:0px;left:0px;width:'+ inc/3+';height:'+inc/3+';background:#ffffff;font-size:1">.</div>'); if (ie&&!o6) document.write("</div></div>"); } function pos(){ h=(ie)?document.body.clientHeight:window.innerHeig ht-20; w=(ie)?document.body.clientWidth:window.innerWidth-20; ry=Math.round(Math.random()*h); rx=Math.round(Math.random()*w); rep=Math.round(Math.random()*3); if (rep == 3)ry=0; if (rep == 2)ry=h; if (rep == 1)rx=0; if (rep == 0)rx=w; py=ry; px=rx; } pos(); function followleader(){ sy=(!ie)?window.pageYOffset:0; sx=(!ie)?window.pageXOffset:0; if (ie) outer.style.top=document.body.scrollTop; for (inc=0; inc < num; inc++){ randomcol=col[Math.floor(Math.random()*col.length)]; temp1=eval(_d+_a+"dots"+inc+_r+_s); temp1.visibility=v; if (inc < num-1){ temp2=eval(_d+_a+"dots"+(inc+1)+_r+_s); temp1.top=temp2.top; temp1.left=temp2.left } else{ temp1.top=py+sy; temp1.left=px; } if (n4)temp1.bgColor=randomcol; else temp1.background=randomcol; } } function bomb(){ ay=MAy-py; ax=MAx-px; angle=Math.round(Math.atan2(ay,ax)*180/Math.PI); if (angle < 0) angle += 360; MAdy=py-MAy; MAdx=px-MAx; distance=Math.floor(Math.sqrt(MAdx*MAdx+MAdy*MAdy) ); go_y = Math.round(vel*Math.sin(angle*Math.PI/180)); go_x = Math.round(vel*Math.cos(angle*Math.PI/180)); py+=go_y; px+=go_x; if (distance < vel) pos(); followleader(); tmr=setTimeout("bomb()",20); } bomb(); function dsbl(){ v=(n4)?"hide":"hidden"; put=true; MAx=0; MAy=0; setTimeout('clearTimeout(tmr)',stopafter+100); } setTimeout('dsbl()',stopafter); //--> </script>
5. Tiêu đề của trang web chạy:

<script language=JavaScript> var txt=" ..:: WelCome To Website | wWw.KyNiemB2.Top1.Vn | Mang Giai Tri Online -> 12B2 THPT EaH'Leo - Daklak - Design : HoangVu Entertainment© -"; var expert=200; // speed of roll var refresh=null; function marquee_title(){ document.title=txt; txt=txt.substring(1,txt.lenghth)+txt.charAt(0); refresh=setTimeout("marquee_title()",expert); } marquee_title(); </script> 

6. Chữ chạy dưới thanh taskbar:

 <SCRIPT language=JavaScript> puchtit=")«-»(..:: Welcome To WwW.NhoOi.Kiss.To ::..)«-»("; letrero2="·.¸¸.·´´¯`··._.·"; letrero1="·.¸¸.·´´¯`··._.·";ultimo1=letr ero1.length-1; ultimo2=letrero2.length-1; tiempo=setTimeout("scroll()",.100); function scroll() { aux1=letrero1.charAt(ultimo1-1); letrero1=aux1+letrero1.substring(0,ultimo1-1); aux2=letrero2.charAt(0); letrero2=letrero2.substring(1,ultimo2+1)+aux2; window.status="(" + letrero1 + ")(" + letrero2 + puchtit + letrero1 + ")(" + letrero2 + ")"; tiempo=setTimeout("scroll()",.100); return true; } // --> </script> 

7. Add bookmark website đặt website làm trang chủ


<a target="blank" <a style="text-decoration: none; " onclick="this.style.behavior='url(#default#homepag e)'; this.setHomePage('http://soctrangdesign.com');" href="http://soctrangdesign.com"> 

8. Không cho save nội dung website:

 <NOSCRIPT><IFRAME src=*.jpg></IFRAME></NOSCRIPT> 

9. Cảnh báo khi thoát website:

<html> <head> <title> Sóc Trăng Design</title> <meta Name="GENERATOR" content="Microsoft FrontPage 5.0"> </head> <body onunload="window.alert(' Đồng Bào Chú Ý ...- Click wWw.SocTrangDesign.cOm !')"> </body> </html> 

10. Tìm kiếm với Goolge:

<!-- Search Google --> <center> <form method="get" action="http://www.google.com.vn/custom" target="_top"> <td nowrap="nowrap" valign="top" align="left" height="32"> <a href="http://www.google.com/"> <img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle" width="75" height="32"></img></a> <input type="text" name="q" size="50" maxlength="255" value=""></input> <input type="submit" name="sa" value="Search"></input> <input type="hidden" name="client" value="pub-1710694852538675"></input> <input type="hidden" name="forid" value="1"></input> <input type="hidden" name="ie" value="UTF-8"></input> <input type="hidden" name="oe" value="UTF-8"></input> <input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH :center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000F F;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input> <input type="hidden" name="hl" value="vi"></input> </td></tr> </form> </center> <!-- Search Google -->

11. Tự động chào hỏi khách viếng thăm sau 1 khoản thời gian:


<SCRIPT LANGUAGE="JavaScript"> <!--Begin datetoday = new Date(); timenow=datetoday.getTime(); datetoday.setTime(timenow); thehour = datetoday.getHours(); if (thehour > 18) display = "Evening"; else if (thehour >12) display = "Afternoon"; else display = "Morning"; var greeting = ("Good " + display + "!"); document.write(greeting); // End --> </script> 

12. Rồng bay trong website:

<DIV id=Layer1 style="Z-INDEX: 1; LEFT: 0px; WIDTH: 900px; Bottom: 0px; POSITION: absolute; HEIGHT: 600px"><EMBED align=right src=" http://soctrangdesign.com/forum/hinh_baiviet/dragon.swf" width=1000 height=600 type=application/x-shockwave-flash wmode="transparent"></DIV> 

13. Countdown Happy New Year 2011 - Tết Nguyên Đán Xuân Tân Mão:


<SCRIPT language=JavaScript1.2> function setcountdown(theyear,themonth,theday){ yr=theyear;mo=themonth;da=theday } //////////CONFIGURE THE COUNTDOWN SCRIPT HERE////////////////// //STEP 1: Configure the countdown-to date, in the format year, month, day: setcountdown(2011,02,03) //STEP 2: Change the two text below to reflect the occasion, and message to display on that occasion, respectively var occasion=" đến<font color=#FF00CC>Tết Nguyên Đán</font> <font color=red>Xuân Tân Mão - <font color=#FF00CC>Chúc mừng năm mới</font>" var message_on_occasion="Happy New Year" //STEP 3: Configure the below 5 variables to set the width, height, background color, and text style of the countdown area var countdownwidth='870px' var countdownheight='25px' var countdowncolor='#00BB00' /// mau`/// var opentags='<font face="Tahoma"><large>' var closetags='</large></font>' //////////DO NOT EDIT PASS THIS LINE////////////////// var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov","Dec") var crosscount='' function start_countdown(){ if (document.layers) document.countdownnsmain.visibility="show" else if (document.all||document.getElementById) crosscount=document.getElementById&&!document.all? document.getElementById("countdownie") : countdownie countdown() } if (document.all||document.getElementById) document.write('<span id="countdownie" style="width:'+countdownwidth+'; color:'+countdowncolor+'"></span>') window.onload=start_countdown function countdown(){ var today=new Date() var todayy=today.getYear() if (todayy < 1000) todayy+=1900 var todaym=today.getMonth() var todayd=today.getDate() var todayh=today.getHours() var todaymin=today.getMinutes() var todaysec=today.getSeconds() var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec futurestring=montharray[mo-1]+" "+da+", "+yr dd=Date.parse(futurestring)-Date.parse(todaystring) dday=Math.floor(dd/(60*60*1000*24)*1) dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1) dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000) )/(60*1000)*1) dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000 ))%(60*1000))/1000*1) //if on day of occasion if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=1&&todayd==da ){ if (document.layers){ document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+message_on_occasion+closeta gs) document.countdownnsmain.document.countdownnssub.d ocument.close() } else if (document.all||document.getElementById) crosscount.innerHTML=opentags+message_on_occasion+ closetags return } //if passed day of occasion else if (dday<=-1){ if (document.layers){ document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+"Occasion already passed! "+closetags) document.countdownnsmain.document.countdownnssub.d ocument.close() } else if (document.all||document.getElementById) crosscount.innerHTML=opentags+"Occasion already passed! "+closetags return } //else, if not yet else{ if (document.layers){ document.countdownnsmain.document.countdownnssub.d ocument.write(opentags+"Còn, "+dday+ " ngày, "+dhour+" giờ, "+dmin+" phút, và "+dsec+" giây nữa là đến "+occasion+closetags) document.countdownnsmain.document.countdownnssub.d ocument.close() } else if (document.all||document.getElementById) crosscount.innerHTML=opentags+" Chỉ còn "+dday+ " ngày, "+dhour+" giờ, "+dmin+" phút, và "+dsec+" giây nữa là"+occasion+closetags } setTimeout("countdown()",1000) } </SCRIPT> 

14. Tuyết rơi trong website:


<html> <head> <title>www.soctrangdesign.com</title> </head> <body> <center> <script LANGUAGE="JavaScript1.2"> <!-- Begin var no = 25; // Số tuyết var speed = 10; // Số càng nhỏ tuyết di chuyển(rơi) càng nhanh var snowflake = "http://soctrangdesign.com/forum/hinh_baiviet/snow.gif"; // Nơi đây chèn hình bông tuyết var ns4up = (document.layers) ? 1 : 0; // Bộ duyệt tìm nạp vào var ie4up = (document.all) ? 1 : 0; var dx, xp, yp; // tọa độ và những vị trí thay đổi var am, stx, sty; // Độ rộng và những bước thay đổi var i, doc_width = 800, doc_height = 600; if (ns4up) { doc_width = self.innerWidth; doc_height = self.innerHeight; } else if (ie4up) { doc_width = document.body.clientWidth; doc_height = document.body.clientHeight; } dx = new Array(); xp = new Array(); yp = new Array(); am = new Array(); stx = new Array(); sty = new Array(); for (i = 0; i < no; ++ i) { dx[i] = 0; // những biến đổi toạ độ tập hợp xp[i] = Math.random()*(doc_width-50); // tập hợp những thay đổi vị trí yp[i] = Math.random()*doc_height; am[i] = Math.random()*20; // tập hợp những thay đổi độ rộng stx[i] = 0.02 + Math.random()/10; // tập hợp những thay đổi bước sty[i] = 0.7 + Math.random(); //tập hợp những thay đổi bước if (ns4up) { // những lớp tập hợp if (i == 0) { document.write("<layer name=\"dot"+ i +"\" left=\"15\" "); document.write("top=\"15\" visibility=\"show\"><img src=\""); document.write(snowflake + "\" border=\"0\"></layer>"); } else { document.write("<layer name=\"dot"+ i +"\" left=\"15\" "); document.write("top=\"15\" visibility=\"show\"><img src=\""); document.write(snowflake + "\" border=\"0\"></layer>"); } } else if (ie4up) { if (i == 0) { document.write("<div id=\"dot"+ i +"\" style=\"POSITION: "); document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: "); document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\""); document.write(snowflake + "\" border=\"0\"></div>"); } else { document.write("<div id=\"dot"+ i +"\" style=\"POSITION: "); document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: "); document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\""); document.write(snowflake + "\" border=\"0\"></div>"); } } } function snowNS() { // hàm Netscape hoạt cảnh chính for (i = 0; i < no; ++ i) { // vòng lặp cho mỗi điểm yp[i] += sty[i]; if (yp[i] > doc_height-50) { xp[i] = Math.random()*(doc_width-am[i]-30); yp[i] = 0; stx[i] = 0.02 + Math.random()/10; sty[i] = 0.7 + Math.random(); doc_width = self.innerWidth; doc_height = self.innerHeight; } dx[i] += stx[i]; document.layers["dot"+i].top = yp[i]; document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]); } setTimeout("snowNS()", speed); } function snowIE() { // hàm IE hoạt cảnh chính for (i = 0; i < no; ++ i) { // vòng lặp cho mỗi điểm yp[i] += sty[i]; if (yp[i] > doc_height-50) { xp[i] = Math.random()*(doc_width-am[i]-30); yp[i] = 0; stx[i] = 0.02 + Math.random()/10; sty[i] = 0.7 + Math.random(); doc_width = document.body.clientWidth; doc_height = document.body.clientHeight; } dx[i] += stx[i]; document.all["dot"+i].style.pixelTop = yp[i]; document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]); } setTimeout("snowIE()", speed); } if (ns4up) { snowNS(); } else if (ie4up) { snowIE(); } // End --> </script> </body> </html> 

15. Chữ ẩn hiện và thay đổi chữ:

<script LANGUAGE="JavaScript"> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://soctrangdesign.com --> <!-- truonghuynh, webmaster@soctrangdesign.com. --> <!-- Begin // add as many or as few messages as you would like var msg=new Array() msg[0]="<CENTER>Chao mung Sóc Trăng Design - soctrangdesign.com ...!</CENTER>"; msg[1]="<CENTER>...Chuc cac ban luon thanh dat va vui ve.</CENTER>"; msg[2]="<CENTER>Just type in \"<A href='http://soctrangdesign.com/'>www.soctrangdesign.com</A>\"</CENTER>"; msg[3]="<CENTER>Cam on cac ban da ghe tham !</CENTER>"; // set your first set of colors. Use as many or as few as you wish. var colors1=new Array("ffffff", "eeeeff", "ddddff", "ccccff", "bbbbff", "aaaaff", "9999ff", "8888ff", "7777ff", "6666ff", "5555ff", "4444ff", "3333ff","2222ff", "1111ff", "0000ff") //set your second set of colors // *** must have exactly the same number of colors as the array above *** var colors2=new Array("ffffff", "ffeeee", "ffdddd", "ffcccc", "ffbbbb", "ffaaaa", "ff9999", "ff8888", "ff7777", "ff6666", "ff5555", "ff4444", "ff3333", "ff2222", "ff1111", "ff0000") //set the height of the display in pixels high=60; //set the width of the display in pixels wide=350; //set the pixel coordinates for the upper left hand corner of the display Xpos=220; Ypos=180; // move the display away from the edges of the b