NYCPHP Meetup

NYPHP.org

[nycphp-talk] More Client-Side Grief

Hans Zaunere zaunere at yahoo.com
Tue Oct 29 19:02:15 EST 2002


--- Adam Fields <fields at surgam.net> wrote:
> On Tue, Oct 29, 2002 at 04:36:20PM -0500, Hans Zaunere wrote:
> > After picking bits from each post, I've finally done something
> like:
> > 
> > -- the PHP script that handles the form POST prints this to the
> popup:
> > 
> > <script language="JavaScript">
> >    if( opener ) {
> >       opener.location.assign('<?=$next?>');
> >       opener.location.reload(true);
> >       window.close();
> >    } else {
> >       window.location.assign('<?=$next?>');
> >    }
> > </script>
> 
> I have one further enhancement to suggest, drawn from a function I
> use elsewhere. In the latter case, if the headers have not yet been
> sent, you'll want to use PHP to generate a redirect header for you
> instead of loading the page and redirecting with javascript. This is
> basically what I'm thinking, although I have yet to test it to see if
> it works consistently:
> 
> --------------------
> 
> function REDIRECT ($url) 
> {
>   if (substr($url, 0, 7) != 'http://') {
>     if (substr($url, 0, 1) == '/') {
>       $url = 'http://'.$_SERVER['HTTP_HOST'].$url;
>     } else {
>       $url = 'http://'.$_SERVER['HTTP_HOST'].'/'.$url;
>     }
>   }
>   if (!headers_sent()) {
>     header('Location: '.$url);
>   } else {
>     print '<script>';
>     print "location.href='".$url."';";
>     print '</script>';
>   }
> }

Originally I had been using this technique, and of course it works
great.  However, when the headers are sent back to the popup (which is
where the form submit happens) I can't find a way to detect that in
JavaScript and use the new URL to refresh the main window.  As far as I
could tell, all the obvious stuff doesn't work, ie: when executing from
the popup, document.location.href always refers to the originally
requested URL.

> I got most of the functionality of my session-based jumpback stack
> working today. Don't know if that'll help you at all.

Sure, I'd be interested in seeing it.

> > Ideally, I would have wished there was a way to read the HTTP
> headers sent from PHP into JavaScript/JScript and then act on them. 
> Supposedly there is
(http://msdn.microsoft.com/workshop/author/dhtml/reference/constants/response_headers.asp)
> > but as with so much client-side, I could never get them to do
> anything.

It's frustrating, after reading the above link, that there's no way to
see the "Location" header that gets sent to a window.  If you run into
anything else I'd be curious.

H



__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/



More information about the talk mailing list