View Full Version : iframe and onclick event

Dec 31st, 2006, 01:50 PM
Hello, I have a page which contains two iframes. On this page I have a hyperlink which when clicked I want both iframes to refresh. Is this possible??

I think the hyperlink should look something like this:

<a href="javascript:void(0);" onclick="some javasacript">click here</a>

If someone could fill in the javascript I would be grateful.


Dec 31st, 2006, 03:03 PM
You will need to be able to identify the iframes, I recommend an id attribute.


function refreshIframes()
var iframe1 = document.getElementById('id1');
var iframe2 = document.getElementById('id2');

iframe1.src = iframe1.src;
iframe2.src = iframe2.src;


<a href="javascript:void(0);" onclick="refreshIframes();">click here</a>

That should work. If you would like to avoid a javascript: url, use this:

<a href="" onclick="refreshIframes(); return false;">click here</a>

Mr J
Dec 31st, 2006, 06:13 PM
Here's another option

<a href="page1.htm" target="iframename1" onclick="window.frames['iframename2'].location='page2.htm' ; return false">Load</a>