javascript help

Discussion in 'JavaScript' started by joesgraphics, Jan 13, 2007.

  1. #1
    Is there a javascrpt like onhover ("click link") so if some 1 hovers a link it will click the link if it is posable i think iv seen it on a site befor but forgot what site. lol
     
    joesgraphics, Jan 13, 2007 IP
  2. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #2
    <a href="http://thelinkhere" onMouseover="document.location='http://thelinkhere';">Some link</a>
     
    kajakske, Jan 13, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    You can save typing the URLs twice by using this.href.

    
    
    <a href="http://thelinkhere" onMouseover="document.location=this.href;">Some link</a>
    
    Code (markup):
     
    nico_swd, Jan 13, 2007 IP
  4. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #4
    The purpose of clicking is to allow the user to confirm an action. If you remove that facility, you cause confusion and mis-operation.
    Here's an alternative - just insert the script in the body, anywhere below the last link and you're done.

    <SCRIPT type='text/javascript'>
    
    LinkCountdown= /**2843295374657068656E204368616C6D657273*/
    {
     /** Insert below the last link in the document **/  
       
     timer:null, defaultText:'', delayTime:0, timeLeft:0,
       
     init:function(secs)
     {
      this.delayTime=this.timeLeft=secs
        
      for(var i=0,dl=document.links,len=dl.length; i<len; i++)
      {
       dl[i].onmouseover=function(){LinkCountdown.go(this)}  
       dl[i].onmouseout= function(){LinkCountdown.stop()}  
      }
     },
     
     go:function(linkRef)
     {
      this.linkRef=linkRef;
      this.url=linkRef.href;
      this.defaultText=this.linkRef.childNodes[0].nodeValue;
      this.timeLeft=this.delayTime;
      this.write(); 
     },
    
     write:function()
     {
      this.linkRef.childNodes[0].nodeValue=this.defaultText+' '+(this.timeLeft>0?this.timeLeft:'!');
      if(this.timeLeft-- < 1)
       window.location=this.url
      this.timer=setTimeout("LinkCountdown.write()",1000);
     },
    
     stop:function()
     {
      clearTimeout(this.timer);
      
      this.linkRef.childNodes[0].nodeValue=this.defaultText;
     }
    }
    
    LinkCountdown.init( 5 ); /** <-- Set the delay seconds  **/
    
    </SCRIPT>
    Code (markup):
     
    Logic Ali, Jan 13, 2007 IP
  5. joesgraphics

    joesgraphics Peon

    Messages:
    206
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    OK thanks for all the help. :)
     
    joesgraphics, Jan 13, 2007 IP