1. مهمان گرامی، جهت ارسال پست، دانلود و سایر امکانات ویژه کاربران عضو، ثبت نام کنید.
    بستن اطلاعیه

ترفند هاي جاوا اسكريپت

شروع موضوع توسط ♥ yakamoz ♥ ‏30/11/10 در انجمن JS

  1. کاربر ویژه

    تاریخ عضویت:
    ‏25/11/10
    ارسال ها:
    8,717
    تشکر شده:
    4,395
    امتیاز دستاورد:
    123
    حرفه:
    Telegram: vahid_yakamoz instagram: vahid_yakamoz
    ترفند شماره 1:
    موضوع : تابع setTimeout
    يكي از توابع جالب جاوا اسكريپت تابع setTimeout هستش. اين تابع باعث مي شود يك كد نه در زمان كنوني بلكه در چندميلي ثانيه (كه ما مي خواهيم)بعد اجرا ميكند.
    اين تابع دو پارامتر دريافت مي كند.
    1- يك رشته از دستورات جاوا اسكريپت كه قرار است اجرا شود.به ياد داشته باشيد كه اين دستور بايد فاقد هرگونه خطاي دستوري باشد.
    2- دومين پارامتر فاصله زماني است كه پس از زمان فراخواني قصد داريم دستور مورد نظر اجرا شود. اين فاصله زماني به ميلي ثانيه وارد مي شود.(هر يك ثانيه 1000 ميلي ثانيه است).
    مثال :

    کد:
    <script type="text/javascript">
    Function showmsg()
    {
    setTimeout("alert('5 Second')",5000)
    }
    </script>



    شاید شما تا به حال این مشکل برای شما افتاده باشید که کسی یا کسانی میان و عکس یا مطالب شما رو بر می دارن و درون وبلاگشون میزارن برای جلوگیری از این راه شما باید یکی از کدهای زیر رو درون وبلاگتون قرار بدید :
    کد اول :
    این کد ار هایلات شدن متن شما جلوگیری می کنه یعنی کسی دیگه نمی تونه مطالب شما رو کپی کنه
    <!-- Start --- http://www.Tar-Fand.Tk--><SCRIPT language=JavaScript1.2>function disableselect(e){return false}function reEnable(){return true}document.onselectstart=new Function ("return false");if (window.sidebar){document.onmousedown=disableselec tdocument.onclick=reEnable}</SCRIPT><!-- End --- http://www.Tar-Fand.Tk-->
    کد دوم :
    این کد یا کدها نیز برای جلوگیری از راست کلیک کردنِ که امکان راست کلیک کردن رو از بازدید کننده وبلاگ شما می گیره .
    کد اول اگر کلیک راست بشه تو وبلاگ شما هیچ پیغامی نمایان نمی شود.
    1 :
    <!-- Start --- http://www.Tar-Fand.Tk--><SCRIPT LANGUAGE="JavaScript">document.oncontextmenu = function(){return false};if(document.layers) {window.captureEvents(Event.MOUSEDOWN);window.onmo usedown = function(e){if(e.target==document)return false;}};else {document.onmousedown = function(){return false}}</script><!-- End --- http://www.Tar-Fand.Tk-->
    2 :
    <!-- Start --- http://www.Tar-Fand.Tk--><script language=JavaScript>m='%3Cscript%20language%3DJavaScript%3E%3C%21--%0D%0A%0D%0Avar%20message%3D%22SORRY : %20 %21%22%3B%0D%0A%0D%0Afunction%20clickIE%28%29%20%2 0%7Bif%20%28document.all%29%20%7Balert%28message%2 9%3Breturn%20false%3B%7D%7D%0D%0Afunction%20clickN S%28e%29%20%7Bif%20%0D%0A%28document.layers%7C%7C% 28document.getElementById%26%26%21document.all%29% 29%20%7B%0D%0Aif%20%28e.which%3D%3D2%7C%7Ce.which% 3D%3D3%29%20%7Balert%28message%29%3Breturn%20false %3B%7D%7D%7D%0D%0Aif%20%28document.layers%29%20%0D %0A%7Bdocument.captureEvents%28Event.MOUSEDOWN%29% 3Bdocument.onmousedown%3DclickNS%3B%7D%0D%0Aelse%7 Bdocument.onmouseup%3DclickNS%3Bdocument.oncontext menu%3DclickIE%3B%7D%0D%0A%0D%0Adocument.oncontext menu%3Dnew%20Function%28%22return%20false%22%29%0D %0A%0D%0A//%20--%3E%3C/script%3E';d=unescape(m);document.write(d);</script><!-- End --- http://www.Tar-Fand.Tk-->
    کد بعدی با پیغامه یعنی اگه راست کلیک کنه یه پیغام برای اون ظاهر میشه :
    <!-- Start --- http://www.Tar-Fand.Tk--><SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">var message="Tar-Fand.Tk";function click(e) {if (document.all) {if (event.button == 2 || event.button == 3 || event.button == 6 || event.button == 7) {alert(message);return false;}}if (document.layers) {if (e.which == 3) {alert(message);return false;}}}if (document.layers) {document.captureEvents(Event.MOUSEDOWN);}document .onmousedown=click;</SCRIPT><!-- End --- http://www.Tar-Fand.Tk-->
    این کد هم با پیغامه با این تفاوت که اگه راست کلیک کنه یه پیغام برای اون ظاهر می شه و اگه دوباره راست کلیک کنه همین طور پیغام دوم براش میاد تا ریستارت کنه.
    <!-- Start --- http://www.Tar-Fand.Tk--><SCRIPT language=JavaScript>document.onmousedown=click;var times=0;var times2=10;function click() {if ((event.button==2) || (event.button==3)) {if (times>=1) { bye() };alert("Tar-Fand.Tk"); times++ } }function bye() {alert("Tar-Fand.Co.Sr");bye() }</SCRIPT><!-- End --- http://www.Tar-Fand.Tk-->
    و کد آخرم اینه که وقتی بازدید کننده کلیک راست می کنه یه پیغام برای اون ظاهر می شه و بعد صفحه چند لحظه می لرزه.
    <!-- Start --- http://www.Tar-Fand.Tk--><SCRIPT>document.onmousedown=click;var times=0;var times2=10;function click() {if ((event.button==2) || (event.button==3)) {if (times>=0) { earthquake() };alert("Tar-Fand.Tk");times++ } };function earthquake () {alert("Tar-Fand.Tk");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);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(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><!-- End --- http://www.Tar-Fand.Tk-->

    افکتهای ماوس


    * .اولین کد حركت كردن كلمه اي در حال چرخش همراه ماوسه:


    <SCRIPT language=JavaScript1.2> <!--//1) set message to displayvar scroller_msg='نام مورد نظر شما'//2) set whether message should auto disappear after x seconds (0=perpetual).//Note that double clicking page will also dismiss messagevar dismissafter=0var initialvisible=0if (document.all)document.write('<marquee id="curscroll" style="position:absolute;width:100px;border:1px solid black;font-size:14px;background-color:#fde6cc;visibility:True">'+scroller_msg+'</marquee>')function followcursor(){//move cursor function for IEif (initialvisible==0){curscroll.style.visibility="visible"initialvisible=1}curscroll.style.left=document.bod y.scrollLeft+event.clientX+10curscroll.style.top=d ocument.body.scrollTop+event.clientY+10}function dismissmessage(){curscroll.style.visibility="hidden"}if (document.all){document.onmousemove=followcursordo cument.ondblclick=dismissmessageif (dismissafter!=0)setTimeout("dismissmessage()",dismissafter*1000)}//--></SCRIPT><!----- Script By Tar-fand.blogfa.com ----></body></html></body></html></body></html> * . کد دوم هم افكتي است که سه رنگ در هم می چرجخن جالبه :<SCRIPT language=JavaScript>var a_Colour="red";var b_Colour="blue";var c_Colour="green";var Size=40;//Alter nothing below !!var YDummy=new Array(),XDummy=new Array(),xpos=0,ypos=0,ThisStep=0;step=0.03;if (document.layers){window.captureEvents(Event.MOUSE MOVE);function nsMouse(evnt){xpos = window.pageYOffset+evnt.pageX+6;ypos = window.pageYOffset+evnt.pageY+16;}window.onMouseMo ve = nsMouse;}else if (document.all){function ieMouse(){xpos = document.body.scrollLeft+event.x+6;ypos = document.body.scrollTop+event.y+16;}document.onmou semove = ieMouse;}function swirl(){for (i = 0; i < 3; i++) { YDummy=ypos+Size*Math.cos(ThisStep+i*2)*Math.sin((ThisSt ep)*6); XDummy=xpos+Size*Math.sin(ThisStep+i*2)*Math.sin((ThisSt ep)*6); }ThisStep+=step;setTimeout('swirl()',10);}var amount=10;if (document.layers){for (i = 0; i < amount; i++){document.write('<layer name=nsa'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+a_Colour+'></layer>');document.write('<layer name=nsb'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+b_Colour+'></layer>');document.write('<layer name=nsc'+i+' top=0 left=0 width='+i/2+' height='+i/2+' bgcolor='+c_Colour+'></layer>');}}else if (document.all){document.write('<div id="ODiv" style="position:absolute;top:0px;left:0px">'+'<div id="IDiv" style="position:relative">');for (i = 0; i < amount; i++){document.write('<div id=x style="position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+a_Colour+';font-size:'+i/2+'"></div>');document.write('<div id=y style="position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+b_Colour+';font-size:'+i/2+'"></div>');document.write('<div id=z style="position:absolute;top:0px;left:0px;width:'+i/2+';height:'+i/2+';background:'+c_Colour+';font-size:'+i/2+'"></div>');}document.write('</div></div>');}function prepos(){var ntscp=document.layers;var msie=document.all;if (document.layers){for (i = 0; i < amount; i++){ if (i < amount-1) { ntscp['nsa'+i].top=ntscp['nsa'+(i+1)].top;ntscp['nsa'+i].left=ntscp['nsa'+(i+1)].left; ntscp['nsb'+i].top=ntscp['nsb'+(i+1)].top;ntscp['nsb'+i].left=ntscp['nsb'+(i+1)].left; ntscp['nsc'+i].top=ntscp['nsc'+(i+1)].top;ntscp['nsc'+i].left=ntscp['nsc'+(i+1)].left; } else { ntscp['nsa'+i].top=YDummy[0];ntscp['nsa'+i].left=XDummy[0]; ntscp['nsb'+i].top=YDummy[1];ntscp['nsb'+i].left=XDummy[1]; ntscp['nsc'+i].top=YDummy[2];ntscp['nsc'+i].left=XDummy[2]; }}}else if (document.all){for (i = 0; i < amount; i++){ if (i < amount-1) { msie.x.style.top=msie.x[i+1].style.top;msie.x.style.left=msie.x[i+1].style.left; msie.y.style.top=msie.y[i+1].style.top;msie.y.style.left=msie.y[i+1].style.left; msie.z.style.top=msie.z[i+1].style.top;msie.z.style.left=msie.z[i+1].style.left; } else { msie.x.style.top=YDummy[0];msie.x.style.left=XDummy[0]; msie.y.style.top=YDummy[1];msie.y.style.left=XDummy[1]; msie.z.style.top=YDummy[2];msie.z.style.left=XDummy[2]; }}}setTimeout("prepos()",10);}function Start(){swirl(),prepos()}window.onload=Start;// --></SCRIPT><!----- Script By Tar-fand.blogfa.com ---->

    آهنگ برای وبلاگ

    با سلام
    امروز کد گذاشتن آهنگ در وبلاگ رو همراه با آموزش قرار دادن آن را در سیستم بلاگفا را برای شما آماده کردم.
    خوب برای این کار ابتدا به قسمت تنظیمات وبلاگ خود بروید و در قسمت ( اسکریپتها و کدهای اختصاصی کاربر برای درج در وبلاگ ( مانند کدهای سیستمهای آمار بازدیدکنندگان یا پخش آهنگ) ) کد زیر را کپی کنید.

    <!------ http://www.Tar-Fand.coo.ir><p align="center" style="margin-top: 0; margin-bottom: 0"><EMBED SRC="آدرس آهنگ مورد نظر" WIDTH=120 HEIGHT=26 LOOP=true type=audio/x-pn-realaudio-plugin><!------ http://www.Tar-Fand.coo.ir></body></html> توضیحاتی کوتاه در مورد کد بالا :
    1) در قسمت آدرس آهنگ مورد نظر شما می تونید آهنگ مورد نظر خودتونو آدرسش رو کپی کنید و به جای این قسمت بزارید مثلاً :
    کد آهنگ چارهای ندارم از رضا صادقی که لینک اونو از سایت Sarzamin.org برداشتم
    http://www.sarzaminmusic.com/Sarzam...Sadeghi - Vaysa Donya/04_ Chareyi Nadaram.mp3
    و در این کد قرار دادم.
    2) در قسمت width می تونید عرض ضبط و در قسمت height هم میتونید ارتفاع آن را مشخص کنید.
    3) در قسمت Loop اگر مقدار آن True باشد بعد از اتمام آهنگ ، آهنگ دوباره شروع به خوندن می کنه ولی اگه مقدار اون False باشه بعد از اتمام آهنگ ضبط Stop میشه.
    اینم کد آهنگ رضا صادقی :
    <!------ http://www.Tar-Fand.coo.ir><p align="center" style="margin-top: 0; margin-bottom: 0"><EMBED SRC="http://www.sarzaminmusic.com/Sarzaminmusic/Persian/128KB/Reza%20Sadeghi%20-%20Vaysa%20Donya/04_%20Chareyi%20Nadaram.mp3" WIDTH=120 HEIGHT=26 LOOP=true type=audio/x-pn-realaudio-plugin><!------ http://www.Tar-Fand.coo.ir></body></html>
    با تشکر