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 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need version of "onClick" for url's that works in all browsers

    Hey all,
    I'm trying to apply to a div element an onClick event that will mimmick a link(send them to a new page). I've got this version:
    Code:
    onClick="window.location.href('http://www.whatever.com')"
    It seems to work fine in IE but not in firefox.
    Here's the full code as applied to the div:
    Code:
    <div class="box" id="boxhover" onClick="window.location.href('http://www.whatever.com')">
    </div>
    I've also tried:
    Code:
    onClick="javascript:window.location.href('http://www.whatever.com');"
    <!-- NOTICE THE ADDITION OF THE SEMICOLON -->
    Once again, fine in IE, not if Firefox. Does anyone have an approach that's bulletproof for all browsers?

    Mark

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    <div class="box" id="boxhover" onClick="window.location.href='http://www.google.com'">Link</div>
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New Coder
    Join Date
    Nov 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, Oh Silent One. I am reaping the bountiful fruits of your wisdom...

    In other words, it works great!!!

    Thanks,
    Mark


  •  

    Posting Permissions

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