Welcome to the Geeks & God Static Archive. Read more »

reload page Only onclose

Joined: 11/28/2008

I wanted to reload an opener page ONCLOSE of the pop-up page

I tried using BODY UNLOAD, but this does it for the page calling another php page as well, which can be the page itself

is there any way, I can do a check on when the user clicks the X on the window to Close

Thanks,

Silpa

Joined: 11/28/2008
Hello Silpa, I just tested

Hello Silpa,

I just tested this and it works well.

Place it as the body tag of your pop-up window.

CODE
<body onUnload="window.opener.location.reload();">

When the pop-up is closed, it will use JavaScript to referesh the page that opened the pop-up.

Let me know how it goes.

Blessings:

Sean

Joined: 11/28/2008
Hi Sean Well I guess I didnt

Hi Sean

Well I guess I didnt word my question right

The Body Unload with the "window.opener.location.reload()" does refresh the opener page

but it does it when i click the submit button on the pop-up as well, as its calling a php script in anohter page,

I want to do it only onCLOSE with clicking X on the pop-up

Thanks,Silpa

Does this make sense?

Joined: 11/28/2008
Hello Silpa: Okay, hopefully

Hello Silpa:

Okay, hopefully I understand correctly.

If I do then,

There are only three normal user actions that will unload the popup window and cause the opening document to referesh:

1) Closing the box by hitting the X

2) Submitting a form in the popup window

3) The user clicking on a link

So, we have a refresh opening window action that is called on any page unlaod, but we don't want it to work for certain user actions, mainly the form submit.

How about having the onlick for the form button change a setting to not let the refresh opening window to trigger?

The following code will do that:

CODE
<html>

<head>

<title>Pop Up Window</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">

<!--

var doIt = 1;

function CloseRefresh()

{

   if (doIt == 1)

    {

       window.opener.location.reload();

   }

}

function unsetDoIt()

{

    doIt = 0;

}

//-->

</script>

</head>

<body onUnload="CloseRefresh()">

<p>Pop Up Window</p>

<form name="form1" method="post" action="">

 <input name="Submit" type="submit" onClick="unsetDoIt()" value="Submit">

</form>

</body>

</html>

This code...

CODE
function CloseRefresh()

{

   if (doIt == 1)

    {

       window.opener.location.reload();

   }

}

...will refresh the opening window if the variable doIt is set to 1. The default value is set to one.

However, this code...

CODE
function unsetDoIt()

{

    doIt = 0;

}

..will change it.

So, I have attached to the form's submit button a call to the unetDoIt() function:

CODE
<input name="Submit" type="submit" onClick="unsetDoIt()" value="Submit">

I have tested it, and it does what it should do. Do you think it will work for what you are trying to do?

Blessings:

Sean

Joined: 11/28/2008
Hey Sean That Javascript is

Hey Sean

That Javascript is pretty neat - I was wondering how you could do that after reading Silpa's post. Very good!

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Thanks bro: I used this

Thanks bro:

I used this approach to write an interesting function that works in IE 6.

It tries to mimick a grab and drag scroll of a page.

You can try it here:

http://christian-web-masters.com/tonyScroll.htm

Take a look:

CODE
<html>

<head>

<script language="JavaScript">

<!--

var doIt = 0;

if (document.layers && doIt == 1) {

   document.captureEvents(Event.MOUSEMOVE);

   document.onmousemove = myScroll;

}

var last = (new Date()).getTime();

function myScroll(e)

{

   var now = (new Date()).getTime();

   if (document.layers && now > (last + 100) && doIt == 1) {

       window.scrollTo(e.screenX - window.screenX - (window.outerWidth - window.innerWidth),e.screenY - window.screenY - (window.outerHeight - window.innerHeight));

       last = now;

   }

   else if (document.all && now > (last + 100) && doIt == 1) {

 

       window.scrollTo(window.event.x,window.event.y);

       last = now;

   }

}

function setDoIt(){

    doIt = 1;

}

function unsetDoIt(){

    doIt = 0;

}

//-->

</script>

</head>

<body  onMouseMove="myScroll()" onmouseup="unsetDoIt()" onselectstart="return false" onmousedown="setDoIt()">

<table width="100%"><tr><td>

<p>

Sed ut perspiciatis unde omnis iste natus error sit voluptatem

accusantium doloremque laudantium, totam rem aperiam, eaque ipsa ab

illo inventore veritatis et quasi architecto beatae vitae dicta sunt

explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut

odit aut fugit, sed quia consequuntur magni dolores eos qui ratione

voluptatem sequi nesciunt.

</p>

......................................

</td></tr></table>

</body>

</html>

Joined: 11/28/2008
Aahh, just like on the Mac!

Aahh, just like on the Mac! Is it worth having an onMouseOut="unsetDoIt()" as well, since I found if I did the grab and moved my mouse out of the window, it would then stay in grab-mode and I would have to click again to stop it. Just an idea.

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Thanks Sean

Thanks Sean

That seems like a great function. I just read it, so I am goign to try it out.

I am sure, it should work and will let you know.

and yeah you got exactly what i meant by how i needed only OnClose

Thanks /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />

Silpa