Click to See Complete Forum and Search --> : Javascript linking


Len
07-03-2003, 07:11 PM
I have just started learning Javascript & I have come 2 a grinding halt with linking... below is the script I'm using on my website which, depending on the time of day, it shows a certain image. What I really want is also to link that certain image to another webpage....any help GREATLY appreciated


<SCRIPT LANGUAGE = 'JavaScript'><!--
var date = new Date();
var hours = date.getHours();
var weekday = date.getDay();
var minutes = date.getMinutes();


if ( (weekday < 1) && (hours >= 7) && (hours < 10) )
document.write("<IMG SRC='images/tod_tbm_lj.gif'>" )
else if ( (weekday < 1) && (hours >= 10) && (hours < 12) )
document.write("<IMG SRC='images/tod_wendshow.gif'>" )
else if ( (weekday < 1) && (hours >= 12) && (hours < 16) )
document.write("<IMG SRC='images/tod_t40.gif'>" )
else if ( (weekday < 1) && (hours >= 16) && (hours < 20) )
document.write("<IMG SRC='images/tod_dees.gif'>" )
else if (weekday < 1)
document.write("<IMG SRC='images/tod_tbm.gif'>" )
else if ( (weekday > 5) && (hours >= 7) && (hours < 12) )
document.write("<IMG SRC='images/tod_tbm_lj.gif'>" )
else if ( (weekday > 5) && (hours >= 12) && (hours < 18) )
document.write("<IMG SRC='images/tod_tbm_spello.gif'>" )
else if ( (weekday > 5) && (hours >= 18) && (hours < 22) )
document.write("<IMG SRC='images/tod_hothits.gif'>" )
else if (weekday > 5)
document.write("<IMG SRC='images/tod_tbm.gif'>" )
else if ( (weekday >= 5 ) && (weekday < 6) && (hours >= 21) )
document.write("<IMG SRC='images/tod_prock.gif'>")
else if ( (hours >= 6) && (hours < 9) )
document.write("<IMG SRC='images/tod_bb_lj.gif'>")
else if ( (hours >= 9) && (hours < 10) && (minutes >= 0) && (minutes < 31) )
document.write("<IMG SRC='images/tod_hot6_lj.gif'>")
else if ( (hours >= 9) && (hours < 12) )
document.write("<IMG SRC='images/tod_tbm_lj.gif'>")
else if ( (hours >= 12) && (hours < 13) )
document.write("<IMG SRC='images/tod_request_spello.gif'>")
else if ( (hours >= 13) && (hours < 16) )
{xonair="tod_tbm_spello"}
else if ( (hours >= 16) && (hours < 17) && (minutes >= 0) && (minutes < 20))
document.write("<IMG SRC='images/tod_net4_spello.gif'>")
else if ( (hours >= 16) && (hours < 18) )
document.write("<IMG SRC='images/tod_tbm_spello.gif'>")
else if ( (hours >= 18) && (hours < 21) )
document.write("<IMG SRC='images/tod_hot30.gif'>")
else
document.write("<IMG SRC='images/tod_tbm.gif'>");
//--></SCRIPT>

</head>

<body>
<div id="Layer42" style="position:absolute; left:462px; top:257px; width:68px; height:62px; z-index:73">
<script language=JavaScript>
document.write('<img src="http://www.mixxfm.com.au/Mallee/images/' + xonair + '.gif">');
</script>


</div>
</body>
</html>

Khalid Ali
07-03-2003, 10:06 PM
Add a function something like this

function openURL(url){
window.open(url,url,'');
}

now in all the document.write statements you can add an onclick event in the image tag something along these lines

document.write("<IMG SRC='images/tod_hot30.gif' onclick='openURL(\"http://www.w3c.org\")'>")

this you should implement for all of th eimages

Len
07-03-2003, 10:37 PM
Thanks Khalid Ali,

It didn't work for me...I have set it all up in a layer thru Dreamweaver & not in the head of the page (so the below is in a layer)
I have cut out all the other if-else parts & only left 1 elseif for you to see ....the page I want link to is bbrekky.html...could u please show me exactly how to do this, or if I need to redesign & maybe place all formulas in the head with the document.write only in the layer.

Your help is already greatly appreciated as I'm pulling my hair out....BTW Im from Vic Aust...u?



<SCRIPT LANGUAGE = 'JavaScript'><!--

function openURL(url){
window.open(url,url,'');
}

var date = new Date();
var hours = date.getHours();
var weekday = date.getDay();
var minutes = date.getMinutes();

else if ( (hours >= 13) && (hours < 16) )
document.write("<IMG SRC='images/tod_tbm_spello.gif' onclick='openURL(\"http://www.mixxfm.com.au/Mallee/bbrekky.html">")>")

//--></SCRIPT>

Khalid Ali
07-03-2003, 10:47 PM
you got it (almost...:D )
just a tiny syntactical error

use this line

document.write("<IMG SRC='images/tod_tbm_spello.gif' onclick='openURL(\"http://www.mixxfm.com.au/Mallee/bbrekky.html\")'>")

Len
07-03-2003, 11:06 PM
Thanks 4 u're help so far Khalid Ali,
We are getting closer .... at least now the gif does come up ...but when I click on the pic nothing happens...once again I have copied the script here...don't know why its not working but it ain't

Cheers

Len


<SCRIPT LANGUAGE = 'JavaScript'><!--

function openURL(url){
window.open(url,url,'');
}

var date = new Date();
var hours = date.getHours();
var weekday = date.getDay();
var minutes = date.getMinutes();


else if ( (hours >= 13) && (hours < 16) )
document.write("<IMG SRC='images/tod_tbm_spello.gif' onclick='openURL(\"http://www.mixxfm.com.au/Mallee/bbrekky.html\")'>")

else
document.write("<IMG SRC='images/tod_tbm.gif'>");
//--></SCRIPT>
</div>

Khalid Ali
07-03-2003, 11:39 PM
Yeah I know..I forgot that name is pretty strict in which characters can be used,try the following

function openURL(url,name){
window.open(url,name,'')
}
document.write("<IMG SRC='images/tod_tbm_spello.gif' onclick='openURL(\"http://www.mixxfm.com.au/Mallee/bbrekky.html\",\"w1\")'>")

see the parameter w1 it should be appropriate for every link you want to opoen if its a unique name then all windows be unique else one window will open all the links in it

Len
07-04-2003, 12:14 AM
thanks Khalid Ali,

As we say here 'youre bloody marvellous'...thank u very much
IT WORKS!!!!!!!!!!!

1 more thing...could u please show me how to choose the size of the window that will open after clicking the link... I only want it to be around half the size of a normal window...

Thanks again

Cheers Len

Khalid Ali
07-04-2003, 12:23 AM
there are multiple approaches for that..
you cna hae a uniform size for all of your windows that will be done.

window.open(url,url,'width=400,height=400');

Len
07-04-2003, 12:31 AM
Thanks matey u r amazing...how did u learn all this...
All works wonderfully...

I shan't pester u anymore (unless I am stumped again <extreme possibility> )

Thanks again



Cheers

Len:)

Khalid Ali
07-04-2003, 12:36 AM
you are welcome ....:D