Forum Moderators: open

Message Too Old, No Replies

Getting Popup Link to Refresh Into Parent Window

My Links work ... but is there an easier way to code this?

         

rockym

10:26 pm on Jul 16, 2003 (gmt 0)

10+ Year Member



Hello all!
I've lurked here for a while (and even posted a few times several months ago ... unfortunately my account expired) and have received a TON of great information.
However, the time has come that i am stumped again...please help me! :)
Ok, at my site, www.widgets.com, i have a popup that comes up after visitors have been at the site for a few seconds that lets them know about our specials for the day.
I managed to get the links from the popup window to load in the parent window (thanks to you guys!).
Some example code of how i do this is (lets say the popup is called "widgpopup.htm"):

<script>
function link1() {
opener.location.href="http://www.widgets.com/redwidget.htm";
self.blur();
}
function link2() {
opener.location.href="http://www.widgets.com/orgwidget.htm";
self.blur();
}
</script>

<a href="widgpopup.htm" onClick="link1()">Red Widgets</a>
<a href="widgpopup.htm" onClick="link2()">Orange Widgets</a>

While this works...(quite well, in fact)...It has its drawbacks, such as clicking any link causing all of the links act as visited links, and i can't just add links onto my table, i have to add new functions for each specific link...while not a big deal, it is time consuming.

So, my question is: I'm new to javascript, and i'm wondering if i can make this any easier or cut out any of the steps to get the same affect: a popup window that loads clicked links into the parent window that generated the popup.

Any help would be appreciated! Thanks!

Rocky

4serendipity

7:14 am on Jul 17, 2003 (gmt 0)

10+ Year Member



Something like the following should suit your needs

<a href="javascript:link1()">Red Widgets</a>
<a href="javascript:link2()">Orange Widgets</a>

This should solve your visited link issue.

A more efficient way would be:

<a href="redwidget.htm" onclick="javascript:opener.location.href='http://www.widgets.com/redwidget.htm'; return false">Red Widgets</a>

<a href="orgwidget.htm" onclick="javascript:opener.location.href='http://www.widgets.com/orgwidget.htm'; return false">Orange Widgets</a>

There is no need for the seperate functions this way

[edited by: tedster at 4:38 pm (utc) on July 19, 2003]
[edit reason] turn off smile faces in the code [/edit]

rockym

4:27 pm on Jul 19, 2003 (gmt 0)

10+ Year Member



Thanks for your help!
I'll try this out today.

Dr_Jive

1:10 am on Jul 20, 2003 (gmt 0)

10+ Year Member



Or you could also try this...

<script>

function link1(element) {

self.opener.location.href=element;
self.blur();
}

</script>

<a href="" onClick="link1('http://www.widgets.com/redwidget.htm')">Red Widgets</a>
<a href="" onClick="link2('http://www.widgets.com/orgwidget.htm')">Orange Widgets</a>

...slightly shorter code
cheers,
dr_j