Click to See Complete Forum and Search --> : Problem with popup box link ...


scarlet.indigo
12-31-2002, 03:31 PM
Hi there ... I'm a javascript newbie, so any help that you all could give me would be very appreciated!

I have a popup box with some text and a link. What I need is a way for the person viewing the popup box to click on the link, and have the popup box close and display the linked page in the original browser window.

An example of what I'm looking for is at http://www.ticketsnow.com. If you click on the "YES" link in the popup box, the box closes, and the linked page appears in the original window.

Thank you in advance!
Jess

khalidali63
12-31-2002, 04:36 PM
Here is one way of doing this.
The code below opens a popup by clicking on a link and then it writes another link in the popup which on click opens a page in the parent windows iframe,you can direct it to parent itself as well.

Khalid
code below

<html>
<head>
<title>Interaction with Pop Up Window - parent</title>
<script>
function openPopup(){
var popupWin = window.open("","popupWin","width=300,height,300,scollbar=no,addressbar=no");
popupWin.document.open();
popupWin.document.write("<a href=\"http://www.cnn.com\" target=\"iframe\">Open CNN in parent Frame</a>");
popupWin.document.close();
}
</script>
</head>

<body>
<a href="javascript:openPopup();">Open Popup</a><br><br>
<iframe src="Blank.html" align="middle" width="80%" height="80%" frameborder="1" name="iframe"></iframe>


</body>
</html>

scarlet.indigo
12-31-2002, 04:55 PM
Close, but not quite. :)

I need the link in my popup box to open in the original window OVER TOP of the currently viewed page. I thought using "target=_parent" on the link would do it, but all that does is open the link in the popup box itself.

I also would like the popup box to close itself when the link is clicked.

http://www.ticketsnow.com pulls this off exactly. Any ideas?

Jess

khalidali63
12-31-2002, 05:14 PM
replace thise line of the existing code

popupWin.document.write("<a href=\"http://www.cnn.com\" target=\"iframe\">Open CNN in parent Frame</a>");

with this one


popupWin.document.write("<a href=\"javascript:top.opener.document.location.href='http://www.cnn.com';self.close();\"\">Open CNN in parent Frame</a>");

scarlet.indigo
12-31-2002, 06:40 PM
Me again :)

That worked perfectly -- the only problem, however, is that the contents of my popup box are contained in their own .htm document, so the document.write code won't work for my situation (and I'm enough of a javascript-newbie that I couldn't reconfigure it myself).

One more time?

Thanks much!
Jess

khalidali63
12-31-2002, 07:40 PM
only need to add page name in this line of code.

var popupWin = window.open("","popupWin","width=300,height,300,scollbar=no,addressbar=no");

in above line add your page name to be opened on the after the parenthesis
window.open("uour pageName.html",


then in the anchor(<a href> tags print this line
<a href=\"javascript:top.opener.document.location.href='http://www.cnn.com';self.close();">Open CNN in parent Frame</a>

change the cnn with your required page

Khalid

scarlet.indigo
12-31-2002, 09:00 PM
Perfect! You're the best, Khalid!

Many thanks,
Jess