Web Analytics Made Easy -
StatCounter link type function....... - CodingForum

Announcement

Collapse
No announcement yet.

link type function.......

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • link type function.......

    hey everybody [like the new board by the way!]

    i've been working on a script for the past couple of hours that types out a link when you put your mouse over it.

    i eventually got it working, but its very temperamental (sp?) and sometimes runs twice when you put your mouse over it and sometimes won't let you click to go to the linked page etc....

    i was wondering if one of you javascript gurus might be able to take a look and perhaps help me out please? i'm a bit out of practise so the code is a bit untidy and probably not that easy to read..... sorry!

    heres the code:

    <script language="javascript">
    <!--
    // pos is the position in the word
    // id is the ID of the element it writes to
    // word is the word it types out

    function typelink(pos,id,word) {
    if (document.all) {

    if (pos <= word.length) {
    document.all[id].innerText = word.substring(0,pos)
    pos++
    setTimeout('typelink(' + pos + ',\'' + id + '\',\'' + word + '\')',100)
    }

    else if (pos > word.length) {
    return true
    }

    }
    }

    //-->
    </script>

    and a link looks like this:

    <a href="http://www.miccheck.co.uk" onmouseover="typelink(0,'newsbox','news')"><font id="newsbox">news</font></a>


    thanks in advance

    dd/mm/yy

  • #2
    I found it worked best in a text box.

    <html>

    <head>
    <script language="javascript">
    <!--

    function typelink(pos,id,word) {
    if (document.all) {

    if (pos <= word.length) {
    document.all[id].innerText = word.substring(0,pos);
    pos++
    pos2 = pos;
    id2 = id;
    word2 = word;
    setTimeout('typelink("' + pos2 + '","' + id2 + '","' + word2 + '")',100)
    }

    else if (pos > word.length) {
    return true
    }

    }
    }

    //-->
    </script>
    </head>

    <body>

    <input type="text" id="newsbox" onmouseover="typelink(0,'newsbox','news');" value="news" style="color:blue; border-style: solid; border-width: 0; width:37;" onclick="location.replace('http://www.miccheck.co.uk')" readonly>

    </body>

    </html>

    Also if you're going to resend the same variables into the function you're currently running I always have problems reusing the names, thats why I made aliases (id2 = id,...)

    Comment


    • #3
      thankyou!!

      hey thanks a lot dude! runs much better like that

      Comment


      • #4
        Hi, just modified the script to support NS6!

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <html>
        <head>
        <title>Type onMouseover</title>
        <script language="javascript">
        // Modifed to support NS6!!
        // Does not work in NS4

        var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1;
        var ns6=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1;

        function typelink(pos,id,word)
        {
        if (ie4||ns6)
        {
        if (pos <= word.length)
        {
        if(ie4)
        {
        document.all[id].innerText = word.substring(0,pos);
        }
        if(ns6)
        {
        document.getElementById(id).innerHTML = word.substring(0,pos);
        }
        pos++
        pos2 = pos;
        id2 = id;
        word2 = word;
        setTimeout('typelink("' + pos2 + '","' + id2 + '","' + word2 + '")',100)
        }
        else if (pos > word.length)
        {
        return true
        }
        }
        }
        </script>
        </head>
        <body bgcolor="#FFFFFF">

        <div id="newsbox" onmouseover="typelink(0,'newsbox','news');" style="font-family:verdana,arial,helvetica; color:#808080; font-weight:bold; font-size:10pt; cursorointer; width:50px" onclick="location.href='http://www.miccheck.co.uk'">news</div>

        </body>
        </html>
        Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal

        Comment

        Working...
        X