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
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can I call a html file from javascript

    If I have a simple variable in Javascript how do i call a different html file depending on its value.

    e.g. if variable = 1 call myfilea.html
    if variable = 2 call myfileb.html
    if variable = 3 call myfilec.html etc.

    Im a bit of a novice javascripter so I might be trying to do something silly or i might be missing something obvious

  • #2
    New Coder
    Join Date
    Dec 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if by calling you mean navigating to it you simply re-set the window.document.location.href

    Code:
    switch(variable) {
      case 1:
         window.document.location.href = 'filea.html';
      break;
    }
    
    /* or */
    
    if(variable == 1)
      window.document.location.href = 'filea.html';
    http://demo.vegui.org - vegUI AJAX framework
    http://www.landsofkazram.com - browser based graphical MMORPG

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts
    if you name your html files lise so:

    htmlfile1.html
    htmlfile2.html
    htmlfile3.html

    then you can create a script that creates the filepath according to the value of the variable.


    <script type=text/javascript>
    var yourvar='???';
    window.location="htmlfile"+yourvar+".html";
    </script>
    I make no attempt at pretending like I'm a professional. I offer help with what knowledge I do have.


  •  

    Posting Permissions

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