[thelist] Close pop-up window and refresh parent page

jeff jeff at members.evolt.org
Mon Jul 31 15:37:54 CDT 2000


minh,

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: From: "Minh Lee Goon" <v7ac at sdsumus.sdstate.edu>
:
: I have a pop-up window that's generated using
: <a
:   href="#"
:   onclick="window.open(...)>.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i would encourage you to move the window.open() to a function that's defined
in the head of your document instead of directly in the onClick event
hander. the advantage of moving it to a function is that you can use it for
multiple instances, you can assign the window.open() method to a variable
which gives you finer control over the window, it's location, it's focus,
etc.

<a
  href="#"
  onClick="newWindow(...)">.

also, i would encourage you to not use a hash as the value of the href
attribute.  instead, if the link is *really* not going anywhere then include
a javascript comment and make sure to return false after you call the
function that opens the window in your onClick event handler.

<a
  href="JavaScript://"
  onClick="newWindow(...); return false">.

if you *are* opening a document in the new window that will work for non-js
users then i would encourage you to use the link in the href and pull that
link into the popup for js users, giving non-js users as much of the
experience as possible.  the only thing they'll be missing is the document
won't be in a popup.

to open the doc in the same window for non-js users:

<a
  href="some_doc.cfm"
  onClick="newWindow(this.href,..); return false">.

alternatively, if you want it to open in a new window for non-js users:

<a
  href="some_doc.cfm"
  target="_blank"
  onClick="newWindow(this.href,..); return false">.

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Now, after processing the form in the pop-up window,
: I'd like to close the window and refresh the parent page.
: Is there a simple way of doing that?
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

in the popup, after your action page has finished running, cflocation the
user to another page that has this (along with the obligatory html):

<script language="JavaScript" type="text/javascript">
  <!--
    opener.location.reload(true);
    self.close();
  // -->
</script>

if you're going to allow access to this document to non-js users, i would
suggest that they not get a new window when clicking the link you mentioned
above.  instead, they view the document in a new window.  in your form, add
a hidden form element.  name it javascript.  give it a value of 0 (zero).
add an onLoad event handler to the form page that changes the value to 1
(one).  in the <body> tag, assuming the form is the first one on the page:

onLoad="document.forms[0].javascript.value = 1;

now, on your action page, prior to performing the cflocation (but after
processing all the form data), do a quick check for the value of this form
element.

<cfif Val(form.javascript)>
  <!--- javascript is enabled --->
  <!--- send them to the page that refreshes --->
  <!--- the opener window and closes the popup --->
  <cflocation url="blah.cfm" addtoken="no">
<cfelse>
  <!--- javascript is disabled --->
  <!--- send them to the page that would --->
  <!--- normally be refreshed from the popup --->
  <cflocation url="blah.cfm" addtoken="no">
</cfif>

:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: Feel free to use CF as well.
:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

since cf is a server-side technology only, it doesn't have access to (nor is
it even aware of) the user environment, including windows.

good luck,

.jeff

name://jeff.howden
game://web.development
http://www.evolt.org
jeff at members.evolt.org





More information about the thelist mailing list