From: Jason Carlton on
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?
From: Thomas 'PointedEars' Lahn on
Jason Carlton wrote:

> 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
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)
From: Jason Carlton on
> 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.
From: Scott Sauyet on
On Dec 16, 2:22 am, Jason Carlton <jwcarl...(a)gmail.com> wrote:
> 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
From: Thomas 'PointedEars' Lahn on
Jason Carlton wrote:

> [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:

<https://developer.mozilla.org/en/DOM/window.open>

> 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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann