homepage Welcome to WebmasterWorld Guest from 54.227.12.219
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Disable refresh button?
I have a good reason! ;)
MatthewHSE




msg:1485585
 8:25 pm on Sep 14, 2005 (gmt 0)

I've got a multi-page form system that I'm setting up, and I'd prefer that users not accidentally refresh the page during the process as this will re-submit some previous data. I know you can use JS to disable the back button; is there anything similar that will disable refresh? (Yes, I find things like this annoying too - but I think this is one instance where it would be a valuable thing to do.)

Thanks,

Matthew

 

Bernard Marx




msg:1485586
 9:22 pm on Sep 14, 2005 (gmt 0)

Er....nope!

MatthewHSE




msg:1485587
 9:27 pm on Sep 14, 2005 (gmt 0)

Er...rats! ;)

Oh well. I guess it's not that big of an issue anyway.

Bernard Marx




msg:1485588
 10:59 pm on Sep 14, 2005 (gmt 0)

Hmmm... then again...

Could something be done using the onunload event handler?
This issue does come up now and again.

Dijkgraaf




msg:1485589
 11:27 pm on Sep 14, 2005 (gmt 0)

You can, but you basically have to disable a other things as well, including right click, the toolbar and button bar (using window.open with options).
So the question is, is it really worth the possibility of anoying your users, or would you be better off just making sure your page can cope with refreshes.

The script below is IE only, but possibly can be adapted for other browsers.

//Disable right mouse click Script
document.onmousedown="if (event.button==2) return false";
document.oncontextmenu=new Function("return false");

document.onkeydown = showDown;

function showDown(evt) {
evt = (evt)? evt : ((event)? event : null);
if (evt) {
if (event.keyCode == 8 && (event.srcElement.type!= "text" && event.srcElement.type!= "textarea" && event.srcElement.type!= "password")) {
// When backspace is pressed but not in form element
cancelKey(evt);
}
else if (event.keyCode == 116) {
// When F5 is pressed
cancelKey(evt);
}
else if (event.keyCode == 122) {
// When F11 is pressed
cancelKey(evt);
}
else if (event.ctrlKey && (event.keyCode == 78 event.keyCode == 82)) {
// When ctrl is pressed with R or N
cancelKey(evt);
}
else if (event.altKey && event.keyCode==37 ) {
// stop Alt left cursor
return false;
}
}
}

function cancelKey(evt) {
if (evt.preventDefault) {
evt.preventDefault();
return false;
}
else {
evt.keyCode = 0;
evt.returnValue = false;
}
}

Don_Hoagie




msg:1485590
 2:31 am on Sep 15, 2005 (gmt 0)

I would highly discourage attempting to disable the refresh button.

There is surely a more appropriate solution..

a Pop-up that says "please for the love of God, do NOT attempt to refresh this page."

a div that loads before anything else that says "please wait for page to load... do not refresh"

I really can't think of any good reason to F with people's browsers (for the user's sake, AND for your site's sake)... and without having seen your site, I would say that your purpose is no more noble than anyone else's.

MatthewHSE




msg:1485591
 12:11 pm on Sep 15, 2005 (gmt 0)

Thanks for the suggestions. Since this form will be getting exclusively type-in traffic, opening a chromeless popup for it really isn't an option. Bernard, thanks for the onunload idea. I'll look around and see if I can find anything that will fit the bill. Unfortunately, I don't know much about JS, so it will likely take me awhile to find a good solution that way. Dijkgraaf, it looks like your code cancels out certain keypresses, which will take care of most of the problems I'd worry about, but do you know of a way to disable the refresh toolbar button as well, without having to use a customized window?

In the end, I guess it won't really matter that much if people refresh the page. It will send the data twice, and some of it may get logged twice depending on when the refresh takes place. But the end-user won't experience problems or anything; I'll just have to deal with it from an admin standpoint. When it comes right down to it, this form is going to have a limited user-base anyway. So I'm probably time ahead by just dealing with extra form data than trying to figure out a way to prevent it.

without having seen your site, I would say that your purpose is no more noble than anyone else's.

Then without having seen my site, please don't try to judge my actions. I never claimed to have a noble purpose, I just think disabling the refresh button would be justified under the circumstances. What's wrong with trying to prevent double submission of form data? It's not like I want to do this on every page of my site; it would only be for a three-page form submission and I'd simply rather get data only once per visitor. I'm pretty big on user-choice myself, so I certainly don't make a habit out of messing with their browser. But I've been on the web long enough to know a potentially valuable feature when I see one - and for this application, disabled refresh would be just that, for everyone concerned.

Don_Hoagie




msg:1485592
 2:36 pm on Sep 15, 2005 (gmt 0)

"without having seen your site" was written as a caveat to the latter statement; not as a set-up for you to make a witty rebuttal.

I would be more than happy to look at your page and prove myself wrong; unfortunately we both know that you can't post your URL, which is why I and everyone else here have to make judgments based on what you're describing. I'm surprised you would have a problem with that, given the fact that you certainly understand that this is the way the forum works.

I respect your knowledge and never insinuated that you don't know what you're doing... I'm just presenting my opinion like everyone else on this forum. If I saw a page that appeared to have trouble loading, and THEN saw that the Refresh button was deactivated, I would most likely assume my browser was acting up and I would quit the app. Hence, my post.

MatthewHSE




msg:1485593
 2:50 pm on Sep 15, 2005 (gmt 0)

Okay, no harm done. Sorry for misunderstanding; I confess to having misjudged your intentions. Incidentally, my "witty rebuttal" was intended only as a mild remonstrance to what I thought you meant - I certainly didn't mean it as a flame (and it doesn't seem like you took it that way, either, for which I thank you).

Good point about a disabled refresh button and quitting the process - I hadn't thought of that. I'd rather deal with duplicate form submissions than lose some submissions altogether. And I really doubt this will be much of an issue anyway, unless maybe people accidentally bump buttons or something. Thanks for sharing your insight on this.

bird




msg:1485594
 2:57 pm on Sep 15, 2005 (gmt 0)

Ignoring duplicate submissions on the server is the correct thing to do. The browser is under the user's control, so any attempt to "solve" the problem there will eventually backfire.

GaryK




msg:1485595
 2:58 pm on Sep 15, 2005 (gmt 0)

What about some JS (or better yet some server-side code) that checks to see if the form has been submitted already and simply disregards refreshes or multiple submissions?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved