View Full Version : Run html page with javascript

Jan 8th, 2010, 01:55 AM
I have a very simple problem, but I can't find the answer. How do I run an html page??

<script type="text/javascript" >
var curdate=new Date();
if (curdate.getMonth()+1 ==1){

document.write("<img src='Images/Menu Pictures/05/homepage.gif'>");
the above line works
document.write("<href src='menu05.htm'>");
The above line doesn't work
if (curdate.getMonth()+1==2){

Jan 8th, 2010, 04:53 AM
open a notepad file..
then paste all ur code there..

<script type="text/javascript" >

Your script here..




Your code here..


go to "File" > "save as" and rename your file name as yourName.html
and hit on save button..

your code "document.write("<href src='menu05.htm'>");"
try change to "document.write("<a href src='menu05.htm'>words</a>");"

and now the file is in html form..double click on it and you will see it in webform..
Hope this help..

Jan 8th, 2010, 04:59 AM
What are you trying to do exactly? Are you trying to include the contents of that menu05.htm page into the current page? If so, then you can't exactly do it that way. You would need a server side language, like php, to do that.

Also, there is no <href> tag.

Jan 8th, 2010, 06:19 AM
I am making a menu out of 15 animated .gif files. I want a different menu each month.

The 15 file names are the same, just in a different directory.

How could I write it to use the currentmonth like this ...

document.write("<img src='Images/Menu Pictures/" & CurrentMonth & "/homepage.gif'>");

Thanks for the suggestions


Jan 8th, 2010, 06:38 AM
You actually almost had it. The string concatenation operator in JavaScript is the + sign tho, not &.

document.write( '<img src="Images/Menu Pictures/"' + CurrentMonth + '"/homepage.gif">' );
Also, you should really use double quotes for html attributes, so use the single quote as the string literal for document.write().

Jan 8th, 2010, 07:22 AM
Fantastic. Thanks a lot. It works great, and a lot simpler than I was going to do it.


Jan 8th, 2010, 07:40 AM
Nice, glad that you got it working. Feel free to post again if you need anything else.