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

Thread: Counting Links

  1. #1
    New Coder
    Join Date
    Mar 2012
    Location
    North West
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Counting Links

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Test Project</title>
    
    <script type="text/javascript">
    var clicks=0;
    function linkClick(){
        document.getElementById('clicked').value = ++clicks;
    }
    </script>
    
    </head>
    
    <body>
    
    <p align="center"><a href="http://www.google.ie" target="_blank" onclick="linkClick()">Google</a></p>
    <p align="center">&nbsp;</p>
    <p align="center"><a href="http://www.google.ie" target="_blank" onclick="linkClick()">Google</a></p>
    <p align="center">&nbsp;</p>
    <p align="center"><a href="http://www.google.ie" target="_blank" onclick="linkClick()">Google</a></p>
    <p align="center">&nbsp;</p>
    
    <td colspan="3" valign="top">You have clicked my links <input id="clicked" size="1" onfocus="this.blur();" value="0" > times</td>	
    <Script Language="JavaScript">
    if ("clicks">3);
    {
    window.open('http://ie.yahoo.com','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
    }
    </Script>
    
    </body>
    
    </html>
    I am a complete novice, I've spend most of today trying to research and learn Javascript.

    I would like my page to keep a count of how many times the links have been opened (this is happening)

    I would like a new pop up window to occur when the count gets to a specif value (this isnt happening) OR maybe to have a new hyperlink to appear that the user can then click on?

    Thanks in advance.
    Last edited by SpongeRob; 03-05-2012 at 11:24 AM. Reason: Solved, thank-you

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Browsers block popup windows unless they are directly triggered by someone clicking a link.

    If the browser is going to allow it then the following should work:

    Code:
    <script type="text/javascript">
    var clicks=0;
    function linkClick(){
        document.getElementById('clicked').value = ++clicks;
        if (clicks>3) {
            window.open('http://ie.yahoo.com','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
            }
    }
    </script>
    Last edited by felgall; 03-03-2012 at 11:02 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    SpongeRob (03-04-2012)

  • #3
    New Coder
    Join Date
    Mar 2012
    Location
    North West
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Felgall, thank-you for that, working perfectly :-)

    Appreciate your assistance :-)


  •  

    Posting Permissions

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