Redirect after child loads, without sending data back from child

J

Jason Carlton

I'm using window.open to open a PDF file in a new window. After it's
loaded, I want to redirect the parent page. The order is important
because the PHP file that I redirect to will delete the PDF file that
was opened.

If I just do this:

onClick="window.open('sample.pdf', 'PDF', 'width=640, height=490,
resizable, scrollbars=1, titlebar=1'); window.location='file.php?
q=del&filename=sample.pdf'; return false">

then it deletes sample.pdf before the browser connects to open it.

Since this is a PDF, there's not a <body...> tag for me to send info
back to the parent. Is there any way for the parent to tell when the
child has fully loaded?
 
T

Thomas 'PointedEars' Lahn

Jason said:
I'm using window.open to open a PDF file in a new window. After it's
loaded, I want to redirect the parent page. The order is important
because the PHP file that I redirect to will delete the PDF file that
was opened.

If I just do this:

onClick="window.open('sample.pdf', 'PDF', 'width=640, height=490,
resizable, scrollbars=1, titlebar=1'); window.location='file.php?
q=del&filename=sample.pdf'; return false">

You need to remove the spaces from the third argument of window.open().
You can remove the `=1's. You should not enforce the window size, and last
time I checked showing the title bar was the default.
then it deletes sample.pdf before the browser connects to open it.

Since this is a PDF, there's not a <body...> tag for me to send info
back to the parent. Is there any way for the parent to tell when the
child has fully loaded?

In that case probably not; it is not even guaranteed that a PDF plugin is
installed so that the PDF document is displayed within the browser. Anyhow,
you have not thought this through. For example, what if client-side
scripting is not (sufficiently) supported or enabled in the first place?


PointedEars
 
J

Jason Carlton

You need to remove the spaces from the third argument of window.open().
You can remove the `=1's.  You should not enforce the window size, and last
time I checked showing the title bar was the default.

At some point (years ago, probably), I had to put the '=1's in there
because I was getting an error (I think on FF 1). I never knew about
the whitespaces, though.

In that case probably not; it is not even guaranteed that a PDF plugin is
installed so that the PDF document is displayed within the browser.  Anyhow,
you have not thought this through.  For example, what if client-side
scripting is not (sufficiently) supported or enabled in the first place?

Removing the file isn't really a necessity, it will just help keep my
server from storing unnecessary files. The PHP script allows the user
to convert a Word document to a PDF, and once they've opened it
there's no real need to keep it stored on my end.

I guess that, instead of the PDF, I could open another PHP script with
an iframe, then load the PDF inside of the iframe. That would give me
a <body...> tag, anyway, so I could report back to the parent when the
page is loaded. I was just hoping that there would be an easier way,
instead of a somewhat clumsy work-around.
 
S

Scott Sauyet

I'm using window.open to open a PDF file in a new window. After it's
loaded, I want to redirect the parent page. The order is important
because the PHP file that I redirect to will delete the PDF file that
was opened.

Your iframe solution might work, but might it not be better to let the
server handle its own cleanup? Can you schedule a job (to run daily,
hourly, or whatever) that deletes all generated PDFs created more
than, say, ten minutes ago?

-- Scott
 
T

Thomas 'PointedEars' Lahn

Jason said:
[Thomas 'PointedEars' Lahn wrote:]
You need to remove the spaces from the third argument of window.open().
You can remove the `=1's. You should not enforce the window size, and
last time I checked showing the title bar was the default.

At some point (years ago, probably), I had to put the '=1's in there
because I was getting an error (I think on FF 1).

Must have been an alpha or beta. AFAIK, it has worked without `=1' or
`=yes' ever since.
I never knew about the whitespaces, though.

You are welcome. Find more information here:

Removing the file isn't really a necessity, it will just help keep my
server from storing unnecessary files. The PHP script allows the user
to convert a Word document to a PDF, and once they've opened it
there's no real need to keep it stored on my end.

Would it be possible to generate and serve the PDF document on-the-fly
instead?
I guess that, instead of the PDF, I could open another PHP script with
an iframe, then load the PDF inside of the iframe. That would give me
a <body...> tag, anyway, so I could report back to the parent when the
page is loaded.

It would require a PDF plugin to work, though.
I was just hoping that there would be an easier way, instead of a somewhat
clumsy work-around.

You could set up a cron job that removes the older files regularly.


Try to keep the attribution line, would you, *please*?


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top