Forum Moderators: open
I'm using a popup (once per browser session) on my index page to optionally direct visitors to another page on the site. The problem though is that the link opens another window.
Does anyone know how i can target the main window already open only?
Additionally, is there a way to auto-close the popup after the link has been clicked?
<url snipped>
Any help much appreciated,
Texas
(edited by: tedster at 7:11 pm (utc) on April 20, 2002)
Here is the script (in body of index page) which calls the popup (once per session)...
<script>
function openpopup(){
var popurl="http://example.com/page_pop.html"
winpops=window.open(popurl,"","width=260,height=200,")
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('poppedup')==''){
openpopup()
document.cookie="poppedup=yes"
}
}
loadornot()
</script>
Now here is the html for the popup page...
<HTML>
<head>
<TITLE>Title</TITLE>
<STYLE>A { TEXT-DECORATION: underline }
</STYLE>
<STYLE>A:hover { COLOR: #FF0000; background-color: #FFFF00 }
</STYLE>
</head>
<BODY>
<table>
<tr>
<td>
<body bgcolor="#FFFFFF" link="#0000FF" vlink="#0000FF">
<div align="center">
<font color="#000000" size=2 face="arial"><p>Message text</p>
<p><font color="#000000" size=2 face="arial"><b> <a href="http://example.com/page_main.html" TARGET="main_window">Send it!</b></a></font>
<p>
<font size="-2">< <a href="javascript:self.close()">close window</a> ></font> </p>
</td>
</tr>
</table>
</BODY>
</html>
Again, my question is, how can I target the /page_main.html page without the link opening another window...and close the popup at the same time?
Texas
(edited by: tedster at 7:16 pm (utc) on April 20, 2002)
<p><font color="#000000" size=2 face="arial"><b> <a href="http://iexample.com/page_main.html" TARGET="main_window">Send it!</b></a></font>
<p>
<font size="-2">< <a href="javascript:self.close()">close window</a> ></font> </p>
Your problem is that there is no "main_window" since you are not using frames.
What I would do is as follows:
In the popup:
<a href="#" onClick="main()">Send it!</a>
Up in your head section have this function:
<script>
function main() {
opener.location.href="http://example.com/page_main.html";
window.close();
}
</script>
That's all there is to it.
(edited by: tedster at 7:18 pm (utc) on April 20, 2002)
Your example worked like a charm. And in case anyone else is interested. Here's what I did...
Between head tags of popup:
<script>
function main() {
opener.location.href="http://inkprintercartridges.com/free-ink-coupon.html";
window.close();
}
</script>
For the link in the popup:
<a href="http://inkprintercartridges.com/free-ink-coupon.html" onClick="main()">Send it!</a>
See it in action here:
Again, many thanks.
Texas