PDA

View Full Version : Can a pop-up button re-direct the originating page?


StudioInferno
09-11-2002, 04:14 AM
can you make a button in a pop-up that changes the url of the original browser window?

umm
09-11-2002, 04:28 AM
insert this script in the popup:


function doMain(goThere){
opener.document.location = goThere
}

...in the body of the popup (around the button) do this:

<a href="javascript:doMain('http://blah.net')"><img src="some_image.gif" border="0" alt=""></a>

that should work

beetle
09-11-2002, 04:29 AM
Why of course!<input type="button" value="Open Google in opener window" onClick="top.opener.location.href='http://www.google.com';" />

StudioInferno
09-11-2002, 04:06 PM
I need to ensure that the users dont just close the pop-up. how whould that be done?

piglet
09-11-2002, 04:17 PM
Hi StudioInferno

Two ways spring to mind -

1. Use a frameless popup - then there's no close button

2. On the popup page call a function in the opening page before it closes:

<BODY onunload="opener.check()">

in the main page have a function:

function check()
{
if (test-of-your-choice)
window.open("yourpopup.htm")
}
Then it'll just re-popup the popup if closed before you want it.

Both things will be very annoying for your visitor - and I don't recommend them!

StudioInferno
09-11-2002, 05:13 PM
ok, i've already got a function in the main page that determines if the user has seen this pop-up before. can I re-call that function with the "onUnload" as if they haven't seen it?

basically, I'm doing an age verification thing. I want the first-time visitor to be asked to declare if they are over 18 or not. I've got the scripting set up to check for a cookie. if no cookie is found, then the pop-up appears. if the visitor declares that they are over 18 then they can view any page without further pop-ups. if they declare that they are under 18 then they are redirected away from the site

if i have this script running then the user can enter the site anywhere and still have to delcare themselves, but only once per session.

if anybody would like to look over what i've got and make some suggestions that would be very much appreciated

piglet
09-12-2002, 01:22 PM
Yes - no problem.

Something like this does the trick:

Your Page:
<HTML><BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var age=0;
function check()
{
if (age==0) window.open("poptest.html")
else if (age=="<18") location.replace('http://google.com')
}
check();
//-->
</SCRIPT>
Your Page...
</BODY>
</HTML>

poptest.html:

<HTML><BODY onunload="opener.check()" onblur="focus()">
<FORM>
How old are you:<BR>
<INPUT TYPE="button" value="Under 18" onclick="opener.age='<18';window.close()">
<INPUT TYPE="button" value="Over 18" onclick="opener.age='18+';window.close()">
</FORM>
</BODY>
</HTML>

StudioInferno
09-12-2002, 07:41 PM
1st off, everybody, thanks for your help.

I've been trying to get the button declaring that they are over 18 to set a cookie so that they won't be harassed by continual pop-ups on each page. I dont think its working...

here's what I've got:

main page-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>

<HEAD>
<TITLE>avs script</TITLE>
<SCRIPT language="JavaScript">
<!-- Hide from older browsers

// Original JavaScript code by Duncan Crombie: dcrombie at chirp.com.au
// Please acknowledge use of this code by including this header.

var avs = document.cookie; // retrieve cookie string

function getCookie(name) { // use: getCookie("name");
var index = avs.indexOf(name + "=");
if (index == -1) return null;
index = avs.indexOf("=", index) + 1;
var endstr = avs.indexOf(";", index);
if (endstr == -1) endstr = avs.length;
return unescape(avs.substring(index, endstr));
}

function centerWindow() {
if (document.all)
var xMax = screen.width, yMax = screen.height;
else
if (document.layers)
var xMax = window.outerWidth, yMax = window.outerHeight;
else
var xMax = 640, yMax=480;

var xOffset = (xMax - 300)/2, yOffset = (yMax - 200)/2;

window.open('avs.html','avs','width=300,height=200,screenX='+xOffset+',screenY='+yOffset+',top='+yOf fset+',left='+xOffset+'');
}

if (!getCookie("agecheck1")) {
centerWindow();
document.cookie = "agecheck1=1";
}

// Stop hiding -->
</SCRIPT>
</HEAD>
<body>
</body>
</html>



pop-up -

<html>
<head>
<title>avs</title>
<SCRIPT language="JavaScript">

function centerWindow() {
if (document.all)
var xMax = screen.width, yMax = screen.height;
else
if (document.layers)
var xMax = window.outerWidth, yMax = window.outerHeight;
else
var xMax = 640, yMax=480;

var xOffset = (xMax - 300)/2, yOffset = (yMax - 200)/2;

window.open('avs3.html','avs','width=300,height=200,screenX='+xOffset+',screenY='+yOffset+',top='+yO ffset+',left='+xOffset+'');
}

</SCRIPT>
</head>
<body OnUnload="centerWindow()";>

<h1 align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b>Age Verification</b></font></h1>

<form name="closer">
<table width="150" border="0" cellpadding="3" align="center">
<tr>
<td>
<div align="center">
<input type=button value="I am over 18" onClick="setCookie("agecheck1", 1);self.close()">
</div>
</td>
<td>
<div align="center">
<input type="button" name="exit" value="I am not over 18" onClick="top.opener.location.href='http://www.google.com';self.close()">
</div>
</td>
</tr>
</table>
</form>

</body>
</html>


what am I doing wrong?

piglet
09-13-2002, 08:42 AM
How about this for a start:

First Page:

1. if (index == -1) return false;
index = avs.indexOf("=", index) + 1;
var endstr = avs.indexOf(";", index);
if (endstr == -1) endstr = avs.length;
return unescape(avs.substring(index, endstr));

can be replaced with

if (index == -1) return false; else return true;


AVS

1. You've not got a setcookie function - and if you did have you'd need to ensure that the path of the cookie included both pages

2. You've tried to nest "'s in this:

<input type=button value="I am over 18" onClick="setCookie("agecheck1", 1);self.close()">

3. top.opener?

onClick="top.opener.location.href-


4. <body OnUnload="centerWindow()";> - what's the ; after the "?

beetle
09-13-2002, 08:55 AM
if (index == -1) return false; else return true;

can be replaced with

return (index != -1);

piglet
09-13-2002, 09:08 AM
OK - lets go the whole hog:

They can drop the function altogether and just test

if (document.cookie.indexOf("agecheck1=")==-1) centerWindow();


Spotted another bug:

if (!getCookie("agecheck1")) {
centerWindow();
document.cookie = "agecheck1=1";
}

What this is doing is opening the window and then setting the cookie immediately....so if you navigate straight away and back again the cookie will be set!

StudioInferno
09-13-2002, 08:01 PM
so, do you mean, like this?

///////MAIN:

<SCRIPT language="JavaScript">
<!-- Hide from older browsers

var avs = document.cookie; // retrieve cookie string

function centerWindow() {
if (document.all)
var xMax = screen.width, yMax = screen.height;
else
if (document.layers)
var xMax = window.outerWidth, yMax = window.outerHeight;
else
var xMax = 640, yMax=480;

var xOffset = (xMax - 300)/2, yOffset = (yMax - 200)/2;

window.open('avs.html','avs','width=300,height=200,screenX='+xOffset+',screenY='+yOffset+',top='+yOf fset+',left='+xOffset+'');
}

if (document.cookie.indexOf("agecheck1=")==-1) centerWindow();

}

// Stop hiding -->
</SCRIPT>



////////AVS:


<html>
<head>
<title>avs</title>
<SCRIPT language="JavaScript">

function centerWindow() {
if (document.all)
var xMax = screen.width, yMax = screen.height;
else
if (document.layers)
var xMax = window.outerWidth, yMax = window.outerHeight;
else
var xMax = 640, yMax=480;

var xOffset = (xMax - 300)/2, yOffset = (yMax - 200)/2;

window.open('avs3.html','avs','width=300,height=200,screenX='+xOffset+',screenY='+yOffset+',top='+yO ffset+',left='+xOffset+'');
}

</SCRIPT>
</head>
<body OnUnload="centerWindow()">

<h1 align="center"><font face="Arial, Helvetica, sans-serif" size="2"><b>Age Verification</b></font></h1>

<form name="closer">
<table width="150" border="0" cellpadding="3" align="center">
<tr>
<td>
<div align="center">
<input type=button value="I am over 18" onClick="setCookie(agecheck1, 1);self.close()">
</div>
</td>
<td>
<div align="center">
<input type="button" name="exit" value="I am not over 18" onClick="top.opener.location.href='http://www.google.com';self.close()">
</div>
</td>
</tr>
</table>
</form>

</body>
</html>

piglet
09-17-2002, 09:04 AM
Hi,

setCookie(agecheck1, 1);


Where's your set cookie script?

1. You've not got a setcookie function - and if you did have you'd need to ensure that the path of the cookie included both pages