PDA

View Full Version : Run html page with javascript



Dynamic42
Jan 8th, 2010, 12: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
}
else
if (curdate.getMonth()+1==2){

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



<html>
<head>
<script type="text/javascript" >

Your script here..

</script>

</head>

<body>

Your code here..

</body>
</html>



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..

Gjslick
Jan 8th, 2010, 03: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.

Dynamic42
Jan 8th, 2010, 05: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

Peter

Gjslick
Jan 8th, 2010, 05: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().

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

Peter

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

-Greg