Forum Moderators: open

Message Too Old, No Replies

needing to add a simple onclick event to a link

         

alseides

7:05 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Currently I have a script to load an iframe with a different page when moused over.

```````````````````````````
here it is:

<script>
function loadIframe(iframeName, url) {
if ( window.frames[iframeName] ) {
window.frames[iframeName].location = url;
return false;
}
else return true;
}
</script>

<a href="page1.html" onmouseover="return loadIframe('iframe', this.href)">Mouse over this link!</a>

<iframe src="iframecontents.html" name="iframe"></iframe>

```````````````````````````

Mousing over the link will swap the contents of the iframe (iframecontents.html) with page1.html. This is working just fine.

What I want to add is make the link go to another page when clicked, ie page2.html (in the same window).

Maybe this is simple question, but I am really not a programmer at all. The source of this code I found while searching around. I just adapted it to my site. So if anyone could show me how to add this, I would really appreciate it.

Thanks.

alseides

8:35 am on Mar 8, 2006 (gmt 0)

10+ Year Member



oh, i might add that it isn't necessary to keep any of the code I currently have. Anything as long as it works.

As long as it allows a link to mouse over and onclick to a different html page in the same link.

khell

9:58 am on Mar 8, 2006 (gmt 0)

10+ Year Member



The modifications below in the <a> tag should do the trick:

<a href="page1.html" onmouseover="return loadIframe('iframe', this.href) onclick="loadIframe('iframe', 'page2.html'); return false;">Mouse over this link / or click it!</a>

alseides

7:19 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



haha. I told you I'm not a programmer. That was easy, thanks a lot!

alseides

7:30 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



Oh I almost forgot, the modification you sent me works great, but what I wanted the onclick to do was to load the link to the entire page, not just the iframe. (only the mouseover loads in the iframe)

thanks.

Fotiman

7:49 pm on Mar 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Isn't this what you want:

<a href="page2.html" onmouseover="return loadIframe('iframe', 'page1.html');">Mouse over this link / or click it!</a>

alseides

9:18 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



yes, that is what I need. Thanks.

I have two more questions concerning this, hoping you could help.

1) For the page that is inside the iframe, is it possible to load a link into the main window, rather than just inside the frame?

2) and also for the code:

loadIframe('navigation', 'navigation/page.html')

is it possible to link to a file farther up in the directory? For example I would want it to link to

loadIframe('navigation', '../../navigation/page.html')
but that doesn't work.

Thanks

alseides

9:20 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



for question #1, I forgot about the target="parent". So I figured that out.

alseides

9:25 pm on Mar 8, 2006 (gmt 0)

10+ Year Member



everything does work now...

thanks for all your help.