Page 1 of 1
[SOLVED] Detecting if the user hit to the Stop button
Posted: Tue Mar 29, 2005 4:25 am
by anjanesh
When a page has finished loading I can use the onload event in body to call some function.
For a process that takes time, say 5 min, what if someone clicks the stop button and I still want to trigger that onload JS function ? Anyway to get that to work ?
Code: Select all
<body onload="alert('done');">
<?
loop
{
// Do something
flush();
}
?>
</body>
How can I detect when the stop button has been clicked in the browser ?
Thanks
Posted: Tue Mar 29, 2005 4:48 am
by CoderGoblin
As far as I know/been told in the past there is nothing you can do. Stop is just that. If you could intercept this and then do things too many people would start to "disable" it.
In reality it is down to the web page design. Show something quickly if necessary. Give them a warning it may take time to process. Give messages telling them it is 10%,90% complete or whatever.
You have two time delays. PHP processing time, which should never really take that long and the time it actually takes to download (Modem speed being key here). 5 minutes php processing time is really too long for users, unless they get messages telling them something is happening. You could potentially have a waiting status bar with a Cancel process link which would link to another page informing the user that the process was cancelled. Give the user other options and they "should" ignore the stop button as their eyes are normally on your web page not the toolbar.
Posted: Tue Mar 29, 2005 5:17 am
by anjanesh
Thanks for the info. Actually this is not really that essential but I thought there was a way.
Code: Select all
<?
echo '<table>';
Loop
{
echo '<tr><td>'.display().'</td></tr>';
flush();
}
echo '</table>';
?>
If Someone hits the Stop button the closing </table> tag never gets printed which is ok for a page php processes fast.
What I have is that it exracts some info from some site and displays one by one. This takes time even on servers - 2 reasons - file_get_contents and preg_match
preg_match really take time.
Thanks anyway
Posted: Tue Mar 29, 2005 5:22 am
by CoderGoblin
Could you use CSS rather than a table as an alternative ?
Posted: Tue Mar 29, 2005 5:27 am
by anjanesh
Till date I've only associated CSS with html tags.
How do you remove table/div tag and repalce it with CSS ?
Btw, The table would be in between <form></form> to perform some action against those rows checked.
So even the last </form> would not be printed.
Posted: Tue Mar 29, 2005 5:36 am
by n00b Saibot
This simple snip does the trick
Code: Select all
function showMSG()
{ alert("e;Why did you press the bloody STOP Button! \r\n Can't Ya Wait for it to load ?"e;) }
document.onstop = showMSG;
Posted: Tue Mar 29, 2005 5:40 am
by anjanesh
Where do I put this document.onstop = showMSG; ?
Its not working in <body onstop="alert('stopped')">
Not working in IE 6 too.
Posted: Tue Mar 29, 2005 5:45 am
by CoderGoblin
I am not suggesting you replace the DIV tags. The key to CSS is to remember you are separating content from format. CSS handles the style or format. The content needs to be "Tagged" to recognise the structure which is where HTML comes in. Tables unfortunately are often in the middle ground. I am not someone who says all tables should be transferred to CSS. Tables do have their place in HTML and content although not always as they are currently used, notably to format columns into columns. (Quick note here I come from a paper documentation background including SGML/XML).
For an example of a tableless design you may want to look at the following article.
[url]ttp://
www.alistapart.com/articles/practicalcss/[/url]
I am sure there are many other articles around.
Posted: Tue Mar 29, 2005 5:46 am
by n00b Saibot
Put it in the head section of the page. whole of it.
your snip doesn't work because onstop then gets associated with document.body object.

Posted: Tue Mar 29, 2005 5:51 am
by CoderGoblin
Well n00b Saibot's code is a somthing new I've learnt but a couple of points to bear in mind...
1) What if javascript is not active ?
2) Still does not close the table (Although I suppose you could use javascript to close the tag but IMO you are starting to make things messy).
Posted: Tue Mar 29, 2005 5:57 am
by n00b Saibot
Yah! dat's the prob with JS. people can turn it off! I hate this feature

I know it is for our own good but knowing there is a functionality/feature that will do our job easily and a great one too and not able to fully rely on its existence. Bah! makes me feel grrrr...
Posted: Tue Mar 29, 2005 5:57 am
by anjanesh
Thanks. It worked.
IE only ! But atleast the majority of the users will get it.
CoderGoblin wrote:Still does not close the table (Although I suppose you could use javascript to close the tag but IMO you are starting to make things messy).
Is there any other way out other than document.write("</table>"); in that onstop function ?
We will need one flush_on_stop() function in PHP.
And thanks for that CSS article.
Posted: Tue Mar 29, 2005 6:03 am
by CoderGoblin
Not as far as I know (but then I have been wrong before). You also need to check if the table has been started... What happens if the user pushes stop before the table is opened ? Shouldn't happen but users being users....
Posted: Tue Mar 29, 2005 6:05 am
by n00b Saibot
Nah! I don't think there is anything else than document.write that will be helpful in your case.
If there comes any other prob. in completing it, sure tell me.
