Log in

View Full Version : way of opening html page in a script



cago
08-16-2013, 01:35 PM
I have a date script that looks up the month and date and then will open js

example


if ((daym==16)&&(month==8)) document.write("<a href=\"august/august_1.html\">August 1 </a>")
if ((daym==26)&&(month==3)) document.write("<script src=\"jsfiles/26.js\"></script>")
if ((daym==27)&&(month==3)) document.write("<script src=\"jsfiles/27.js\"></script>")
if ((daym==28)&&(month==3)) document.write("<script src=\"jsfiles/28.js\"></script>")
if ((daym==29)&&(month==3)) document.write("<script src=\"jsfiles/29.js\"></script>")
if ((daym==30)&&(month==3)) document.write("<script src=\"jsfiles/30.js\"></script>")
if ((daym==31)&&(month==3)) document.write("<script src=\"jsfiles/30.js\"></script>")


what i need to do is on the date to open a html file


i have writen in the past all the information in the html file into a js file, but it takes up a lot of time

is there a way to have a document.LOAD("august_1.html"> when the date is reached

example

if ((daym==16)&&(month==8)) document.load("august_16.html")
if ((daym==17)&&(month==8)) document.load("august_17.html")
if ((daym==18)&&(month==8)) document.load("august_18.html")


any ideas on this????

molendijk
08-16-2013, 08:11 PM
You mean something like this?

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
var daym=new Date().getDate(), month=new Date().getMonth()+1;
function load_file_corresponding_to_date()
{
if(daym==16 && month==8){$('body').load("august_16.html")};
if(daym==17 && month==8){$('body').load("august_17.html")};
if(daym==18 && month==8){$('body').load("august_18.html")}
}
</script>
</head>

<body onload="load_file_corresponding_to_date()">

cago
08-17-2013, 07:55 PM
yes that is the idea, however the images do not load.

I am not running this from a website


All the text loads fine but no images

is there a way without using:
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

this script????

jscheuer1
08-17-2013, 08:14 PM
Yes, but there's a lot of code involved to duplicate what jQuery can do in this regard. I'd actually recommend using a more recent version of jQuery, like 1.9.1.

Once the page is live, users will have it (jQuery) cached, so it's not a big deal. So many sites use it that almost everyone already has it in their cache.

The fact that the images aren't showing up is troublesome. Perhaps their paths are incorrect. Their paths must be correct for the location of the page that they're being imported to, not for the location of the page that they're being imported from.

But if you're happy just replacing the page, you don't need to worry about any of that or jQuery:


<script type="text/javascript">
var daym=new Date().getDate(), month=new Date().getMonth()+1;
function load_file_corresponding_to_date()
{
if(daym==16 && month==8){window.location.replace("august_16.html");}
if(daym==17 && month==8){window.location.replace("august_17.html");}
if(daym==18 && month==8){window.location.replace("august_18.html");}
}
</script>

molendijk
08-17-2013, 08:40 PM
Yes, that's the way to do it if you don't want to use Jquery. Put:

if(daym==16 && month==8){window.location.replace("august_16.html")};
etc., just as John suggested.

As for the images, they should load if they do load when your august-files are accessed directly. What's the content of your jsfiles?