Alou
New Member
Posts: 10
inherit
223156
0
Jan 27, 2016 18:16:07 GMT -8
Alou
10
July 2015
alou
|
Post by Alou on Aug 9, 2015 20:34:15 GMT -8
I don't know if there is already something for this, but here is basically what I am looking for: a plugin that makes the classical "Are you sure you want to leave this webpage?" message come up. It doesn't have to be customizable, all I need is something so that if you accidentally hit backspace while not directly typing and the webpage tries to go back, or you hit close at the top of the tab thing, the message will come up to ensure you mean to do it. I have a forum with a lot of writing, so accidental backspacing and tab-closing during multitasking happens a lot, and any help would be very appreciated!
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Aug 10, 2015 2:37:09 GMT -8
I don't know if there is already something for this, but here is basically what I am looking for: a plugin that makes the classical "Are you sure you want to leave this webpage?" message come up. It doesn't have to be customizable, all I need is something so that if you accidentally hit backspace while not directly typing and the webpage tries to go back, or you hit close at the top of the tab thing, the message will come up to ensure you mean to do it. I have a forum with a lot of writing, so accidental backspacing and tab-closing during multitasking happens a lot, and any help would be very appreciated! See if this will work: support.proboards.com/thread/548204/external-link-confirmationIf not, you can add one manually. <script language="javascript">
function unloadMsg(){
msg = "Stop! Hammer Time."
return msg;
}
function setUnload(on){
window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true);
</script> Adding that in your global header or footer should do the trick
|
|
Alou
New Member
Posts: 10
inherit
223156
0
Jan 27, 2016 18:16:07 GMT -8
Alou
10
July 2015
alou
|
Post by Alou on Aug 10, 2015 11:31:32 GMT -8
I don't know if there is already something for this, but here is basically what I am looking for: a plugin that makes the classical "Are you sure you want to leave this webpage?" message come up. It doesn't have to be customizable, all I need is something so that if you accidentally hit backspace while not directly typing and the webpage tries to go back, or you hit close at the top of the tab thing, the message will come up to ensure you mean to do it. I have a forum with a lot of writing, so accidental backspacing and tab-closing during multitasking happens a lot, and any help would be very appreciated! See if this will work: support.proboards.com/thread/548204/external-link-confirmationIf not, you can add one manually. <script language="javascript">
function unloadMsg(){
msg = "Stop! Hammer Time."
return msg;
}
function setUnload(on){
window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true);
</script> Adding that in your global header or footer should do the trick This is exactly what I need! However, is there any way to make it strictly appear on thread creation or normal pages? Regardless, thank you for the code! This will be very useful.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Aug 10, 2015 12:09:41 GMT -8
See if this will work: support.proboards.com/thread/548204/external-link-confirmationIf not, you can add one manually. <script language="javascript">
function unloadMsg(){
msg = "Stop! Hammer Time."
return msg;
}
function setUnload(on){ if(window.location.href.indexOf('')!=-1){return} window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true);
</script> Adding that in your global header or footer should do the trick This is exactly what I need! However, is there any way to make it strictly appear on thread creation or normal pages? Regardless, thank you for the code! This will be very useful. <script language="javascript">
function unloadMsg(){
msg = "Stop! Hammer Time."
return msg;
}
function setUnload(on){
if(window.location.href.indexOf('thread/new/')==-1&&window.location.href.indexOf('thread/new/')==-1){return}
window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true);
</script> I have it set for thread/new/ however I don't know what you mean by normal pages. If you have some kind of indicator at what a normal page is, I will add that for you.
|
|
Alou
New Member
Posts: 10
inherit
223156
0
Jan 27, 2016 18:16:07 GMT -8
Alou
10
July 2015
alou
|
Post by Alou on Aug 10, 2015 17:23:12 GMT -8
This is exactly what I need! However, is there any way to make it strictly appear on thread creation or normal pages? Regardless, thank you for the code! This will be very useful. <script language="javascript">
function unloadMsg(){
msg = "Stop! Hammer Time."
return msg;
}
function setUnload(on){
if(window.location.href.indexOf('thread/new/')==-1&&window.location.href.indexOf('thread/new/')==-1){return}
window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true);
</script> I have it set for thread/new/ however I don't know what you mean by normal pages. If you have some kind of indicator at what a normal page is, I will add that for you. Ah, yes, this is perfect. The only other pages I'd need it for is for editting pages, and replying to threads. Not sure what I was trying to say so foolishly with normal pages, but that is basically the only thing left I need! Thank you so much for your help!
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Aug 11, 2015 0:48:56 GMT -8
<script language="javascript">
function unloadMsg(){
msg = "Stop! Hammer Time."
return msg;
}
function setUnload(on){
if(window.location.href.indexOf('thread/new/')==-1&&window.location.href.indexOf('thread/new/')==-1){return}
window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true);
</script> I have it set for thread/new/ however I don't know what you mean by normal pages. If you have some kind of indicator at what a normal page is, I will add that for you. Ah, yes, this is perfect. The only other pages I'd need it for is for editting pages, and replying to threads. Not sure what I was trying to say so foolishly with normal pages, but that is basically the only thing left I need! Thank you so much for your help! <script language="javascript"> function unloadMsg(){ msg = "Stop! Hammer Time." return msg; } function setUnload(on){ if(window.location.href.indexOf('thread/new/')==-1&&window.location.href.indexOf('thread/edit/')==-1&&window.location.href.indexOf('post/new/')==-1){return} window.onbeforeunload = (on) ? unloadMsg : null;
}
setUnload(true); </script> maybe that will work
|
|
Alou
New Member
Posts: 10
inherit
223156
0
Jan 27, 2016 18:16:07 GMT -8
Alou
10
July 2015
alou
|
Post by Alou on Aug 11, 2015 10:00:31 GMT -8
This is perfect, thank you so so much!
|
|
inherit
Official Code Helper
65613
0
1
Apr 15, 2024 17:01:41 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,870
December 2005
horace
|
Post by Chris on Aug 11, 2015 21:47:15 GMT -8
Keep in mind that Proboards uses the onbeforeunload event for its own purposes (e.g. notifying about pending AJAX requests) so this might be overwriting their handler or one set by some other plugin. It might be prudent to check for and save a reference to any existing function assigned to onbeforeunload then calling that referenced function from within your own handler as a courtesy and to avoid breaking functionality.
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Aug 11, 2015 23:39:42 GMT -8
Keep in mind that Proboards uses the onbeforeunload event for its own purposes (e.g. notifying about pending AJAX requests) so this might be overwriting their handler or one set by some other plugin. It might be prudent to check for and save a reference to any existing function assigned to onbeforeunload then calling that referenced function from within your own handler as a courtesy and to avoid breaking functionality. Hadn't thought about it personally. I just copied a code from the internet and threw in some mumbo jumbo. Honestly javascript events aren't my strong-suit. I really doubt that a plugin or proboards has anything important on the onbeforeunload event on those pages. And frankly my knowledge cannot overcome such an issue if it arises due to an overwrite. Not to stop anyone else from adapting it.
|
|
inherit
Official Code Helper
65613
0
1
Apr 15, 2024 17:01:41 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,870
December 2005
horace
|
Post by Chris on Aug 14, 2015 21:21:02 GMT -8
I really doubt that a plugin or proboards has anything important on the onbeforeunload event on those pages. No biggie P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓, but one use case on those particular pages would of course be the attachment system which uses it to cleanup unused files off the Proboards server if the user decided not to make the post using those files they just uploaded. Guarding against the situation (because I am sure you would want others coders to be considerate of your codes as well) would require the addition of two lines: - save the current handler if one exists
var old_onbeforeunload = window.onbeforeunload;
- call that saved handler from within your own handler to keep the chain unbroken
old_onbeforeunload.apply(this,arguments);
It should also be noted that the reason why addEventlistener/attachEvent was not used in this case is because certain browsers (non-webkit) do not recognize this as a valid event using that method but the old Netscape event method ("there can be only one") works. This DOM1 event method however requires courtesy on the part of the code writer to look out not only for himself but for others that may have need of that event as well. Note that event listeners cannot be registered for the onbeforeunload event with the addEventListener and attachEvent methods (only Safari and Google Chrome support it). For a cross-browser solution, register the event handler in HTML (with the onbeforeunload attribute of the body element) or with the onbeforeunload inline event property of the window object
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Aug 15, 2015 11:43:05 GMT -8
This is perfect, thank you so so much! I think eton is suggesting I do this with my function to not overwrite any data accidentally. However I'm not sure if that is correct. <script language="javascript"> function unloadMsg(){ msg = "Stop! Hammer Time." return msg; } function setUnload(on){ if(window.location.href.indexOf('thread/new/')==-1&&window.location.href.indexOf('thread/edit/')==-1&&window.location.href.indexOf('post/new/')==-1){return} var old_onbeforeunload = window.onbeforeunload; window.onbeforeunload = (on) ? unloadMsg : old_onbeforeunload.apply(this,arguments); } setUnload(true); </script>
|
|
inherit
Official Code Helper
65613
0
1
Apr 15, 2024 17:01:41 GMT -8
Chris
"'Oops' is the sound we make when we improve"
8,870
December 2005
horace
|
Post by Chris on Aug 16, 2015 4:19:09 GMT -8
Thank you for that response P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓, what you have there now will prematurely run the original handler *if* your handler is not attached else run your handler in lieu of the original handler which still leaves the old handler out in the cold. The Proboards handler as you can see below needs to shoot off an AJAX request to the server upon page close telling it to cleanup any files the user may have abandoned. The return message from the event is not important in some browsers and is in fact ignored (i.e. Firefox displays a standard "leave page" message instead to avoid those official looking "Virus Infection!!" scam messages) but the procedure that occurs in that original handler needs to be performed everytime (that cleanup MUST occur). // If attachments are added to a post and the post is never submitted, // send the file ids to the attachment clean up manager. window.onbeforeunload = function () { if (runCleanUp) { proboards.ajax({ url : proboards.route('cleanup_attachment'), data : { ids : fileIds }, async : false }); return 'If you leave the page now, your attachment(s) will be discarded.'; } }; });
A slight modification to the assignment line such as window.onbeforeunload = (on) ? unloadMsg : old_onbeforeunload; would be sufficient to retain any preexisting handlers but if your handler does take control then it would be pretty nice to call the old handler from within your handler so it can do whatever it still needs to do. function unloadMsg(){ //pay it forward if("function" == typeof old_onbeforeunload){ old_onbeforeunload.apply(this,arguments); } msg = "Stop! Hammer Time." return msg; }
|
|
inherit
223820
0
Mar 14, 2017 3:20:24 GMT -8
beastboybrown
44
August 2015
beastboybrown
|
Post by beastboybrown on Oct 26, 2015 13:55:55 GMT -8
This does not work for my board at all. I tested by leaving to Tumblr/Bricklink and it didn't show the warning :/
|
|
inherit
201984
0
Sept 11, 2023 1:23:07 GMT -8
P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓
Using My Talents Elsewhere
3,314
November 2013
pastuleo23
|
Post by P̌̓aͧś̀t̀u͒le͆o͂2̀3̃̓ on Oct 27, 2015 2:14:48 GMT -8
This does not work for my board at all. I tested by leaving to Tumblr/Bricklink and it didn't show the warning :/ This is a code specifically for the edit pages. If u want a general leaving alert for tumblr then u should add one of the few plugins in the plugin library.
|
|