Welcome to WebmasterWorld Guest from 34.204.173.36

Forum Moderators: open

Message Too Old, No Replies

SE friendly Javascript linking with pop-up windows

Trying to combine 2 scripts

     
11:23 am on Aug 18, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 31, 2002
posts:284
votes: 0


I've got a script that allows me to open a pop-up window using javascript and <a href="popup-link.html" ...>


<script>
function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+','
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
</script>

<a title="link opens in a new window" onclick="NewWindow(this.href,'popup','700','234','no');return false;" href="popup-link.html">

and a bit of js code that will link back from the pop-up window to the main window


<a href="javascript:void()" onClick="opener.parent.location.href('/mainwindow.html')">Main</a>

Without resorting to <noscript>, which I know *can* do the job perfectly well, I was wondering whether there is some way I can combine the this.href from the first bit into the opener.parent from the second, so that the href="javascript:void()" can be replaced with the actual URL: href="/mainwindow.html"

1:19 pm on Aug 18, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0


Adam_C:

I'm not totally clear on what you are aiming for, but you should just be able to do:

<a href="/mainwindow.html" onclick="window.opener.location.href(this.href)">Main</a>

But I don't think you even need to set the href...it shouldn't have changed since the popup opened, should it? If you don't need to set the href, you can do something like:

<a href="/mainwindow.html" onclick="window.opener.focus(); return false;">Main</a>

Which will bring the parent window back into focus above the popup w/o reloading it.

Jordan

1:51 pm on Aug 18, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 31, 2002
posts:284
votes: 0


The first suggestion does work, in that the link opens in the main window, but it also opens in the pop-up.

I don't want the pop-up window to change. I could easily close this window onclick, but I dont want to have to do that.

The second suggestion doesn't open the link. What I want to do is open a different URL to the one that contains the original link that opened tht pop-up.

1:56 pm on Aug 18, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:July 26, 2003
posts:881
votes: 0

Adam_C:

Ahh, I see. The first one should do the trick, I just forgot the return false. Doh! :)

<a href="/mainwindow.html" onclick="window.opener.location.href(this.href); return false;">Main</a>

The return false tells the browser to cancel the click event so that the link href doesn't load as the page href in the popup.

Jordan

2:11 pm on Aug 18, 2003 (gmt 0)

Full Member

10+ Year Member

joined:Aug 31, 2002
posts:284
votes: 0


ahh cool

Sorted now

thanks

5:51 pm on Sept 3, 2003 (gmt 0)

New User

10+ Year Member

joined:Aug 28, 2003
posts:4
votes: 0


I've read the above and could use this peace of information, but beside opening a site in my windowopener i want the popup to close!

Is this possible with the above scripting?

6:36 pm on Sept 5, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 5, 2001
posts:392
votes: 0


so is

<a href="http://widget.com" onclick="window.opener.location.href(this.href); return false;">Main</a>

going to be seen as a link to widget.com (by, say, google) even though it's only popping a window that could be to anywhere?