...

View Full Version : Can I call a html file from javascript



ingie001
12-14-2006, 08:03 PM
If I have a simple variable in Javascript how do i call a different html file depending on its value. :confused:

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

vegu
12-14-2006, 08:22 PM
if by calling you mean navigating to it you simply re-set the window.document.location.href



switch(variable) {
case 1:
window.document.location.href = 'filea.html';
break;
}

/* or */

if(variable == 1)
window.document.location.href = 'filea.html';

brandonH
12-15-2006, 04:42 AM
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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum