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 to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    loading a page dependant on conditions

    I am developing a course. I would like to display certain pages, depending on the Operating system.
    I do not think that javascript can load a page. So I have tried the following:
    In html I have:
    [CODE]
    <a class=header-button href=nextpage()>
    Next
    </a>
    [CODE]

    In javascript I have:
    [CODE]
    function nextpage()
    {
    return "WTL01S02aa.html";
    }
    [CODE]

    The above was just to see if it would work.
    When I click on the link I get an error that it could not find nextpage()

    I have tried the simplest solution. It did not work. Is there a solution?
    Thanks in advance
    John

  • #2
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    Your problem is that you have mixed Javascript and HTML. You could use something like:
    Code:
    <a class=header-button href="javascript:nextpage()">Next</a>
    but this is deprecated.

    Much better to use:
    Code:
    <a class=header-button href="#" onclick="nextpage();">Next</a>
    Your function nextpage needs to change the document location, not just return a URL.
    Code:
    function nextpage()
    {
    document.location="WTL01S02aa.html";
    return false;
    }
    The return false cancels the href attribute.

    This code has not been tested, I do not have my references to hand. You should check on the exact syntax of document location.

    John

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thank you. That is exactly what I needed. Throughout the course I use links to move from page to page. I would like to avoid mixing with buttons.
    The function works perfectly.
    John


  •  

    Posting Permissions

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