Jumat, 19 November 2010

Kumpulan Javascript

. Rabu, 19 Agustus 2009
JavaScript adalah bahasa pemrograman yang khusus untuk halaman web agar halaman web menjadi lebih hidup. Kalau dilihat dari suku katanya terdiri dari dua suku kata, yaitu Java dan Script. Java adalah Bahasa pemrograman berorientasi objek, sedangkan Script adalah serangkaian instruksi program. Berikut adalah contoh Kumpulan Javascript :
  1. Script anti drag dan anti melihat text. Taruh skript dibawah ini diantara <head> dan <title>.
    <script type="text/javascript">

    /***********************************************
    * Disable select-text script- © Dynamic Drive (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/

    //form tags to omit in NS6+:
    var omitformtags=["input", "textarea", "select"]

    omitformtags=omitformtags.join("|")

    function disableselect(e){
    if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
    return false
    }

    function reEnable(){
    return true
    }

    if (typeof document.onselectstart!="undefined")
    document.onselectstart=new Function ("return false")
    else{
    document.onmousedown=disableselect
    document.onmouseup=reEnable
    }

    </script>
  2. Script anti klik kanan. Taruh skript ini setelah <body>
    <script language=JavaScript>
    <!--

    //Disable right mouse click Script
    //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
    //For full source code, visit http://www.dynamicdrive.com

    var message="ganti tulisan ini dengan pesan kamu!";

    ///////////////////////////////////
    function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
    }

    function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
    if (e.which==2||e.which==3){
    alert(message);
    return false;
    }
    }
    }

    if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
    }

    document.oncontextmenu=new Function("alert(message);return false")

    // -->
    </script>
  3. Tulisan berjalan untuk status bar blog/web kamu.   Taruh skript ini di setelah <body>  dan pada pada Body  kamu tambahin  yang tulisan biru    <body  onLoad="scrollit(100)">
    <SCRIPT>
    <!--
    function scrollit(seed) {
    var m1 = "Selamat datang di www.web site kamu .com";
    var m2 = " Terima kasih atas kunjungannya";
    var m3 = " Saya harap dapat bermanfaat!";
    var m4 = "";
    var msg=m1+m2+m3+m4;
    var out = " ";
    var c = 1;
    if (seed > 100) {
    seed--;
    cmd="scrollit("+seed+")";
    timerTwo=window.setTimeout(cmd,100);
    }
    else if (seed <= 100 && seed > 0) {
    for (c=0 ; c < seed ; c++) {
    out+=" ";
    }
    out+=msg;
    seed--;
    window.status=out;
    cmd="scrollit("+seed+")";
    timerTwo=window.setTimeout(cmd,100);
    }
    else if (seed <= 0) {
    if (-seed < msg.length) {
    out+=msg.substring(-seed,msg.length);
    seed--;
    window.status=out;
    cmd="scrollit("+seed+")";
    timerTwo=window.setTimeout(cmd,100);
    }
    else {
    window.status=" ";
    timerTwo=window.setTimeout("scrollit(100)",75);
    }
    }
    }
    //-->
    </SCRIPT>
  4. Status bar untuk blog/web sobat dengan efek ketik. Kamu taruh skript ini setelah <body>
    <!--

       http://www.geocities.com/CollegePark/Quad/3400
       http://javacentral.home.ml.org
       http://www.page4life.nl/javacentral/index.htm

       (c) 1997 Semian Software, Script by: Michiel steendam
       Modify and use anyway you want, just mention this site.
       -->

      <SCRIPT>
      <!-- Hide from old browsers

      // All you have to do is put another text in the variable message.
      // Don't forget to break all lines with a ^
      // When you do not place a ^ at the end of all the message, the
      // message will not repeat

      message     = "ini adalah contoh status bar dengan effect ketik^" +
                    "kamu bisa mengganti tulisan ini sesuka kamu^" +
                    "terima kasih atas kunjungan nya^" +
                    "semoga bermanfaat^" +
                    "thanks for visit my web www.arifinpage.tk^" +
                    "^"
      scrollSpeed = 25
      lineDelay   = 1500

      // Do not change the text below //

      txt         = ""

      function scrollText(pos) {
        if (message.charAt(pos) != '^') {
          txt    = txt + message.charAt(pos)
          status = txt
          pauze  = scrollSpeed
        }
        else {
          pauze = lineDelay
          txt   = ""
          if (pos == message.length-1) pos = -1
        }
        pos++
        setTimeout("scrollText('"+pos+"')",pauze)
      }

      // Unhide -->
    scrollText(0)
      </SCRIPT>
  5. Status bar dengan efek datang bertautan. Taruh skript ini setelah </body>
    <SCRIPT LANGUAGE="JavaScript">
    <!--// Copyright 1996 - Tomer and Yehuda Shiran
    // This example will appear in our forthcoming book on JavaScript.
    // Feel free to "steal" this code provided that you leave this notice as is.
    // Additional examples from the book can be found at http://www.geocities.com/SiliconValley/9000/
    // For more information contact Tomer or Yehuda Shiran <yshiran@iil.intel.com>

    // set speed of banner (pause in milliseconds between addition of new character)
    var speed = 10

    // decrease value to increase speed (must be positive)
    // set pause between completion of message and beginning of following message
    var pause = 1500

    // increase value to increase pause
    // set initial values
    var timerID = null
    var bannerRunning = false

    // create array
    var ar = new Array()

    // assign the strings to the array's elements
    ar[0] = "Welcome to my home page"
    ar[1] = "I hope you enjoy "
    ar[2] = "terima kasih atas kunjungan nya"
    ar[3] = "semoga bermanfaat!"

    // assign index of current message
    var message = 0

    // empty string initialization
    var state = ""

    // no value is currently being displayed
    clearState()

    // stop the banner if it is currently running
    function stopBanner() {   
        // if banner is currently running   
        if (bannerRunning)       
        // stop the banner       
        clearTimeout(timerID)   
        // timer is now stopped   
        timerRunning = false
    }

    // start the banner
    function startBanner() {   
        // make sure the banner is stopped   
        stopBanner()   
        // start the banner from the current position   
        showBanner()
    }

    // assign state a string of "0" characters of the length of the current message
    function clearState() {   
        // initialize to empty string   
        state = ""   
        // create string of same length containing 0 digits   
        for (var i = 0; i < ar[message].length; ++i) {       
            state += "0"   
        }
    }

    // display the current message
    function showBanner() {   
        // if the current message is done   
        if (getString()) {       
            // increment message       
            message++       
            // if new message is out of range wrap around to first message       
        if (ar.length <= message)           
            message = 0       
            // new message is first displayed as empty string       
            clearState()       
            // display next character after pause milliseconds       
            timerID = setTimeout("showBanner()", pause)   
        }
        else {       
            // initialize to empty string       
            var str = ""       
            // built string to be displayed (only character selected thus far are displayed)       
        for (var j = 0; j < state.length; ++j) {           
            str += (state.charAt(j) == "1") ? ar[message].charAt(j) : "     "       
        }       
        // partial string is placed in status bar       
        window.status = str       
        // add another character after speed milliseconds       
        timerID = setTimeout("showBanner()", speed)   
        }
    }

    function getString() {   
        // set variable to true (it will stay true unless proven otherwise)   
        var full = true   
        // set variable to false if a free space is found in string (a not-displayed char)   
        for (var j = 0; j < state.length; ++j) {       
            // if character at index j of current message has not been placed in displayed string       
            if (state.charAt(j) == 0)           
            full = false   
        }   
        // return true immediately if no space found (avoid infinitive loop later)   
        if (full) return true   
        // search for random until free space found (braoken up via break statement)   
        while (1) {       
            // a random number (between 0 and state.length - 1 == message.length - 1)       
            var num = getRandom(ar[message].length)       
            // if free space found break infinitive loop       
        if (state.charAt(num) == "0")           
            break   
        }   
        // replace the 0 character with 1 character at place found   
        state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)   
        // return false because the string was not full (free space was found)   
        return false
    }

    function getRandom(max) {   
        // create instance of current date   
        var now = new Date()       
        // create a random number (good generator)   
        var num = now.getTime() * now.getSeconds() * Math.random()   
        // cut random number to value between 0 and max - 1, inclusive   
        return num % max
    }
    startBanner()
    // -->
    </SCRIPT>
  6. Mengganti warna scroll naik turun dan kiri kanan. Taruh skript ini setelah <head> paling atas untuk warna Codenya cari sendiri ya...he ..he..
    <STYLE TYPE="text/css"><!--
     BODY {
      scrollbar-arrow-color:#0000ff;
      scrollbar-base-color:#ffffff;
      scrollbar-shadow-color:#000000;
      scrollbar-face-color:#ffffff;
      scrollbar-hilight-color:#ffffff;
      scrollbar-dark-shadow-color:#000000;
      scrollbar-3D-light-color:#6e91b4;
     }
    //--></STYLE>
  7. Efek cursor kiss and love. Taruh skript ini di setelah <head>
    <style type="text/css">
    <!--
    h1 {
      color:#cc3333;
      font-family:"Comic Sans MS",Helvetica;
    }
    h3 {
      color:#993333;
      font-family:"Comic Sans MS",Helvetica;
    }
    .kisser {
      position:absolute;
      top:0;
      left:0;
      visibility:hidden;
    }
    -->
    </style>

    <script language="JavaScript1.2" type="text/JavaScript">
    <!-- cloak

    //Kissing trail- By dij8 (dij8@dij8.com)
    //Modified by Dynamic Drive for bug fixes
    //Visit http://www.dynamicdrive.com for this script

    kisserCount = 15 //maximum number of images on screen at one time
    curKisser = 0 //the last image DIV to be displayed (used for timer)
    kissDelay = 1000 //duration images stay on screen (in milliseconds)
    kissSpacer = 50 //distance to move mouse b4 next heart appears
    theimage = "http://www.dynamicdrive.com/dynamicindex13/lips_small.gif" //the 1st image to be displayed
    theimage2 = "http://www.dynamicdrive.com/dynamicindex13/small_heart.gif" //the 2nd image to be displayed


    //Browser checking and syntax variables
    var docLayers = (document.layers) ? true:false;
    var docId = (document.getElementById) ? true:false;
    var docAll = (document.all) ? true:false;
    var docbitK = (docLayers) ? "document.layers['":(docId) ? "document.getElementById('":(docAll) ? "document.all['":"document."
    var docbitendK = (docLayers) ? "']":(docId) ? "')":(docAll) ? "']":""
    var stylebitK = (docLayers) ? "":".style"
    var showbitK = (docLayers) ? "show":"visible"
    var hidebitK = (docLayers) ? "hide":"hidden"
    var ns6=document.getElementById&&!document.all
    //Variables used in script
    var posX, posY, lastX, lastY, kisserCount, curKisser, kissDelay, kissSpacer, theimage
    lastX = 0
    lastY = 0
    //Collection of functions to get mouse position and place the images
    function doKisser(e) {

      posX = getMouseXPos(e)
      posY = getMouseYPos(e)
      if (posX>(lastX+kissSpacer)||posX<(lastX-kissSpacer)||posY>(lastY+kissSpacer)||posY<(lastY-kissSpacer)) {
        showKisser(posX,posY)
        lastX = posX
        lastY = posY
      }
    }
    // Get the horizontal position of the mouse
    function getMouseXPos(e) {
      if (document.layers||ns6) {
        return parseInt(e.pageX+10)
      } else {
        return (parseInt(event.clientX+10) + parseInt(document.body.scrollLeft))
      }
    }
    // Get the vartical position of the mouse
    function getMouseYPos(e) {
      if (document.layers||ns6) {
        return parseInt(e.pageY)
      } else {
        return (parseInt(event.clientY) + parseInt(document.body.scrollTop))
      }
    }
    //Place the image and start timer so that it disappears after a period of time
    function showKisser(x,y) {
      var processedx=ns6? Math.min(x,window.innerWidth-75) : docAll? Math.min(x,document.body.clientWidth-55) : x
      if (curKisser >= kisserCount) {curKisser = 0}
      eval(docbitK + "kisser" + curKisser + docbitendK + stylebitK + ".left = " + processedx)
      eval(docbitK + "kisser" + curKisser + docbitendK + stylebitK + ".top = " + y)
      eval(docbitK + "kisser" + curKisser + docbitendK + stylebitK + ".visibility = '" + showbitK + "'")
      if (eval("typeof(kissDelay" + curKisser + ")")=="number") {
        eval("clearTimeout(kissDelay" + curKisser + ")")
      }
      eval("kissDelay" + curKisser + " = setTimeout('hideKisser(" + curKisser + ")',kissDelay)")
      curKisser += 1
    }
    //Make the image disappear
    function hideKisser(knum) {
      eval(docbitK + "kisser" + knum + docbitendK + stylebitK + ".visibility = '" + hidebitK + "'")
    }

    function kissbegin(){
    //Let the browser know when the mouse moves
    if (docLayers) {
      document.captureEvents(Event.MOUSEMOVE)
      document.onMouseMove = doKisser
    } else {
      document.onmousemove = doKisser
    }
    }
    window.onload=kissbegin
    // decloak -->
    </script>
    Taruh script dibawah ini di bawah </body>
    <script language="JavaScript" type="text/JavaScript">
    <!-- cloak
    // Add all DIV's of hearts
    if (document.all||document.getElementById||document.layers){
    for (k=0;k<kisserCount;k=k+2) {
      document.write('<div id="kisser' + k + '" class="kisser"><img src="' + theimage + '" alt="" border="0"></div>\n')
      document.write('<div id="kisser' + (k+1) + '" class="kisser"><img src="' + theimage2 + '" alt="" border="0"></div>\n')
    }
    }

    // decloak -->
    </script>
  8. Ok dech, Selamat mencoba yach . . . Good Luck . . .

Tidak ada komentar:

Posting Komentar