Greasemonkey script help
1
Name:
Anonymous
2007-11-30 21:15
Ok /prog/. I'm trying to make a Greasemonkey script to prevent me from accidentally leaving a certain page.
How would I go about doing this? I'm pretty sure I have to use 'window.onbeforeunload', but I'm not really sure how.
This is what I currently have, which does not work.
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "Are you sure you want to exit this page?";
}
What am I doing wrong?
2
Name:
Anonymous
2007-11-30 21:49
awesome troll
3
Name:
Anonymous
2007-11-30 22:03
>awesome troll
Seriously though, I'm not a troll. After some testing, I found this works in IE, but not in Firefox (which is what I need).
Any idea how I could make this work?
4
Name:
Anonymous
2007-11-30 22:05
Use IE, problem solved.
5
Name:
Anonymous
2007-11-30 22:10
window.onbeforeunload=function(){
var f=arguments.callee;
window.onbeforeunload=function(){f();};
return false;
};
6
Name:
Anonymous
2007-11-30 22:21
I can't use IE, the point of using FF is so this script can load on certain pages automatically (via Greasemonkey).
7
Name:
Anonymous
2007-11-30 22:23
@5
Doesn't seem to work =/
8
Name:
Anonymous
2007-11-30 22:29
>>3
ok then... don't return a string. there is a function for opening up a combo.
9
Name:
Anonymous
2007-11-30 22:33
>>8
Sorry... what?
I have little to no experience with JS.
Would you mind posting an example code that would work?
10
Name:
Anonymous
2007-11-30 22:36
On the assumption this isn't a troll, confirm() will do what you need.
11
Name:
Anonymous
2007-11-30 22:39
>>10
No, I'm not. I'm just a friggin noob.
So would I add that at the beginning or at the end, or where?
12
Name:
Anonymous
2007-11-30 22:40
I don't know if it works, but confirm() opens up a dialogue box. experiment a little.
13
Name:
Anonymous
2007-11-30 22:41
also, it returns a value, true or false. And the returning value of a function in an event may represent the cancelation of the event, in this case, closing the window.
14
Name:
Anonymous
2007-11-30 22:47
>>13
I'm still lost. Assuming you don't want to spend another hour explaining how this works, maybe you could just post a working snippet of code?
15
Name:
Anonymous
2007-11-30 22:50
I also tried this, which didn't work
window.onbeforeunload = function (oEvent) {
oEvent.returnValue = "blah";
}
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
16
Name:
Anonymous
2007-11-30 22:59
OP here, something interesting...
the code in
>>15 sort of works -- the box pops up when the page LOADS, instead of when you attempt to leave.
17
Name:
Anonymous
2007-11-30 23:05
Any help at all for a noob who just wants to prevent himself from accidentally leaving a page? =/
18
Name:
Anonymous
2007-11-30 23:06
lrn2XPCNativeWrapper
19
Name:
Anonymous
2007-11-30 23:08
window.onbeforeunload = function(){
return prompt("You are a fucking idiot.");
}
20
Name:
Anonymous
2007-11-30 23:09
>>18
Look, instead of directing me to do possibly hours of research just to get a measly ten line piece of code to work, couldn't you just post a working one in about 60 seconds?
21
Name:
Anonymous
2007-11-30 23:11
>>19
Good try, but it doesn't work either.
22
Name:
OP
2007-11-30 23:16
Would really appreciate some help right about now.
23
Name:
Anonymous
2007-11-30 23:24
The following works in FF as a standalone HTML page, but I can't get it work through Greasemonkey. Any suggestions?
<script language = javascript>
window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}
</script>
24
Name:
Anonymous
2007-11-30 23:57
25
Name:
Anonymous
2008-11-10 19:50
nigg e r
26
Name:
Anonymous
2009-03-06 11:16
Accidentally LAUNCHED IT A meme obviously has to parse something hence THERE IS I just compiled the program and nothing happens He then calls his.
27
Name:
Anonymous
2010-11-14 12:50