SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Austin, Texas
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Linking a Div Tag with Javascript

    My problem is basically that I need some way to make it so that when a user clicks anywhere in a div tag (not just on text), they get redirected to another page just like a normal <a href="....">asdf</a> tag. Can anyone help me out with a bit of code to do this?

    I myself can program in PHP and a little Perl but I don't know much Javascript. I know enough to make the status line have the url in it and the pointer to change but I can't figure out how to make the actual link.

    Getting the text inside a div tag to become link-able is easy enough, but I can't figure out how to make the blank space linkable.

    Any help is appreciated...
    Actively seeking additional clients: PHP / MySQL Development
    Years of experience in PHP, MySQL, Server Admin, etc.
    Nathan Malone @ ProPHPDevelopmentBlog.com

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the div must have some content or a backgroundColor

    PHP Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    <!--
    function 
    Link(url){
     
    window.top.location=url;
    }
    //-->
    </script></head>

    <body>
    <div style="width:100px;height:100px;border:solid black 1px;"
    onclick="Link('http://www.vicsjavascripts.org.uk');"
    >fred</div>
    </body>

    </html> 

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Austin, Texas
    Posts
    225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect! It works great and is exactly what I need. Thank you!
    Actively seeking additional clients: PHP / MySQL Development
    Years of experience in PHP, MySQL, Server Admin, etc.
    Nathan Malone @ ProPHPDevelopmentBlog.com


Bookmarks

Posting Permissions

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