...

View Full Version : Repeating Events



Stevesparty
07-17-2007, 07:39 AM
I am making a toolbar for a website (using frames) which will have many links on it. I want to try to find someway to be able to click one of the links and have that link continuously load in the "main" frame. Any help would be appreciated as I am a relative "noob" when it comes to Javascript... Unfortunately I don't have any code that would be helpful to post but if you want me to try and explain things clearer please just say so.

mcjwb
07-17-2007, 01:39 PM
Isn't that done in just html with the "target" attribute of a link?
e.g.

<a href="someUrl" taget="frameName">link text</a>

NancyJ
07-17-2007, 02:07 PM
I'm guessing theres more too it than that since the thread title is 'repeating events' and the OP says they want to 'continuously' load the page in the frame.

I think you want something like



<script language="JavaScript">
<!--
var timer = null;
var link = null;

function IClickedALink(url)
{
clearInterval(timer);
link = url
timer = setInterval(reloadFrame, 1000);
}

function reloadFrame()
{

window.top.frames["myFrame"].location.href = link;
}

//-->
</script>

Stevesparty
07-17-2007, 03:55 PM
Thank you this looks like what I want, the only problem is I'm having trouble implementing it. I know I should be using an "onclick" command in my links but I'm confused about how exactly to set it up right.

NancyJ
07-17-2007, 06:01 PM
show us what you've got and we can correct you. Otherwise we have to guess and thats much less productive

Stevesparty
07-17-2007, 11:38 PM
This is just the relevant code and the sites are just examples. When you click the links it takes you to the site but I really don't have any clue how to get javascript things to work right...


<body bgcolor="#003366" >
<font size="2" color="#FF0000"><b>Links: </b></font><font color="#000000" size="2">


<font color="#FFFFFF" size="2">●</font><font color="#ff0000" size="2">
<a href="http://www.megatokyo.com" onclick="javascript:IClickedALink(mega)" target="main">Megatokyo</a>
<font color="#FFFFFF" size="2">●</font><font color="#ff0000" size="2">
<a href="http://www.gmail.com" onclick="javascript:IClickedALink(gmail)" target="main">Gmail</a>



<script language="JavaScript">
<!--
var timer = null;
var link = null;

function IClickedALink(mega)
{
clearInterval(timer);
link = url
timer = setInterval(reloadFrame, 1000);
}

function reloadFrame()
{

window.top.frames.main.location.href = "http://megatokyo.com";
}

//-->
</script>



<script language="JavaScript">
<!--
var timer = null;
var link = null;

function IClickedALink(gmail)
{
clearInterval(timer);
link = url
timer = setInterval(reloadFrame, 1000);
}

function reloadFrame()
{

window.top.frames.main.location.href = "http://www.gmail.com";
}

//-->
</script>

mcjwb
07-18-2007, 04:29 PM
Now I understand what you meant by continuously load!
You can use the code posted by NancyJ like so;

<html>
<head>
<script type="text/javascript">
<!--
var timer = null;
var link = null; // global variable to hold url of page to refresh.
function IClickedALink(url)
{
clearInterval(timer);
link = url
timer = setInterval(reloadFrame, 5000);
}
function reloadFrame()
{
window.top.frames.main.location.href = link;
}
//-->
</script>
</head>
<body bgcolor="#003366" >
<font size="2" color="#FF0000"><b>Links: </b></font><font color="#000000" size="2">

<font color="#FFFFFF" size="2">*</font><font color="#ff0000" size="2">
<a href="http://www.megatokyo.com" onclick="IClickedALink(this.href);" target="main">Megatokyo</a>
<font color="#FFFFFF" size="2">*</font><font color="#ff0000" size="2">
<a href="http://www.gmail.com" onclick="IClickedALink(this.href);" target="main">Gmail</a>

</body>
</html>

You pass the url of the link into the function, therefore you can reuse the same function for each link.

Stevesparty
07-18-2007, 10:35 PM
Thank You!!! It works perfectly. Although... Is there a way I can add a button to make it stop?

mcjwb
07-18-2007, 10:47 PM
Yep.
the javascript:

function stopReload(){
clearInterval(timer);
}

The html:

<input type="button" value="Cancel" onclick="stopReload()">

Stevesparty
07-19-2007, 02:17 AM
Thanks again for all the help, it works like a charm!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum