Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with onClick and onMousedown

    Hi all,

    My browser is firefox.

    I have the piece of code

    <html>
    <head>
    <script type="text/Javascript">

    function load(url,event)
    {
    location.href=url;
    }

    </script>
    </head>
    <body>
    <a href="http://www.yahoo.com" onClick="load('http://www.google.com'); return false;">Yahoo</a>
    </body>
    </html>

    The code works fine when i press left button. But it will not redirect me to google when i press both middle and right(open link in new tab).

    Then i tried this.

    <html>
    <head>
    <script type="text/Javascript">

    function load(url,event)
    {
    var button = event.which;
    //document.write(button);

    if(button==1)
    {
    window.location = url;
    }

    if(button==2)
    {
    window.open(url);
    }

    }

    </script>
    </head>
    <body>
    <a href="http://www.yahoo.com" onMouseDown="load('http://www.google.com',event); return false;">Yahoo</a>

    </body>
    </html>

    It is displaying button values but unable to redirect. So How can i redirect to google when i click yahoo link in all the three cases.

    regards
    kiran

  • #2
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    use document.location instead of window.location or location.href

    document.location.href is a good way to retrieve the location of the document you're looking at but document.location is the way to assign
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •