Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Event-driven?

13 views
Skip to first unread message

morellik

unread,
Oct 9, 2012, 5:09:00 AM10/9/12
to
Dear all,

I don't know if what I want to do is related to event driven, so I expose my problem.
I'm developing a web portal where people can query for metals in biology. The query results can be downloaded but the zip file creation keep a long time. I would that when an user click on download link, the file creation starts and the user can visit other pages inside the portal. When the creation file is finished a message or the download box appears on the visiting user's page.

Is it possible? If yes, which technique I've to learn or which libraries?

Thanks in advance
Enrico

Erwin Moller

unread,
Oct 9, 2012, 5:30:14 AM10/9/12
to
The easiest approach is to open a new window where the request for
zipcreation is processed and that will offer a download when the actual
zip arrives.
That way you have a different page where the request is handles
serverside, and the page that started it all can be replaced so your
visitors can continue browsing your site.

Problem is that many people use popup blockers.

You might want to add a message that they should allow the popup, or
offer a downloadlink and add an explanation: "Please open in new
window/tab".

More sophisticated solutions exist, that will interrupt any page on your
site when the zip is ready (via polling and XHR), but this is quite
cumbersome and possibly more error-prone.

Regards,
Erwin Moller

--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens

morellik

unread,
Oct 9, 2012, 6:10:08 AM10/9/12
to
Thanks,

but there isn't technique that when an user submit or query something works in background and advise the user when it has finished in pages different from the submitted page?

All js libraries that I founded works on the same page, no one permits to catch an action and display results in other pages.

Erwin Moller

unread,
Oct 9, 2012, 6:52:11 AM10/9/12
to
[You replied to yourself, not my posting.]

Javascript (in browsers) work on one page because that is how it is
implemented by webbrowsers.
HTTP protocol isn't designed to have an active state with the server.
And since javascript in a webbrowser lives in that environment, you have
to re-initialize whatever state you desire with each pageload.

A few hints to relieve this constraint a little are:
1) If you want to create some state with the server, you have to use
things like sessions.
2) If you want to remember things in the browser (persistence), use
cookies or DOM storage (and Web storage).
3) If you want to query the server on regular intervals, have a look at
XHR (Ajax).

Option 3 could help you, but you have to implement it at every page on
your site.

I advise you to use a new window for waiting/downloading your zipfile.

Evertjan.

unread,
Oct 9, 2012, 8:34:46 AM10/9/12
to
morellik wrote on 09 okt 2012 in comp.lang.javascript:

> I don't know if what I want to do is related to event driven,

No, it is not. Better start a new thread next time.

> so I
> expose my problem. I'm developing a web portal where people can query
> for metals in biology. The query results can be downloaded but the zip
> file creation keep a long time. I would that when an user click on
> download link, the file creation starts and the user can visit other
> pages inside the portal. When the creation file is finished a message
> or the download box appears on the visiting user's page.

> Is it possible?

Easier is to send them an [serverside generated] email on [serverside]
completion with a temporary link to that zip-file. Serverside garbage
collection of such files seems necessary btw.

Only serverside javascript could be involved to keep this on topic here.

> If yes, which technique I've to learn

The technique advocated in this NG is javascript.

> or which libraries?

Your "or" says it all.

One does only "learn to thrust" libraries, as the act as black boxes.
If you know the library inside out you won't need it, because a dedicated
script is in your reach and is much safer and usually faster as well.

The trust usually is betrayed by lack of quality an consistence, imho.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Danny

unread,
Oct 9, 2012, 3:45:14 PM10/9/12
to
I'd say as way to separate the processes, as suggested before by Erwin Moller and others, use a new window, they're correct by the way, popup blockers very likely may block a window.open(), there are criteria however on what's an UNREQUESTED window and a REQUESTED window, and popup blockers work within such criteria. Anyhow, the way to get around that, is use markup new-windows :), target="_blank", in the form, thus the form will end up submitting to a newly opened window, separating the processes from both windows. Worse case scenario, the form will open in a Tab rather than a window. Try as -> http://www.webdevout.net/test?016&raw

As you can see I load a 2nd page 2secs after submission, the form submits to _blank and other page can load on afterwards, why the delay? to allow the submission process to take place before removing the page/form.

morellik

unread,
Oct 12, 2012, 4:00:47 AM10/12/12
to
On Tuesday, October 9, 2012 9:45:14 PM UTC+2, Danny wrote:
> I'd say as way to separate the processes, as suggested before by Erwin Moller and others, use a new window, they're correct by the way, popup blockers very likely may block a window.open(), there are criteria however on what's an UNREQUESTED window and a REQUESTED window, and popup blockers work within such criteria. Anyhow, the way to get around that, is use markup new-windows :), target="_blank", in the form, thus the form will end up submitting to a newly opened window, separating the processes from both windows. Worse case scenario, the form will open in a Tab rather than a window. Try as -> http://www.webdevout.net/test?016&raw
>
>
>
> As you can see I load a 2nd page 2secs after submission, the form submits to _blank and other page can load on afterwards, why the delay? to allow the submission process to take place before removing the page/form.

Thanks for your example. Very nice.
0 new messages