1

How to change the text of this function script?:

window.onbeforeunload = function(e) { return 'Are you sure you want to leave this page? You will lose any unsaved data.'; };

i want to translate the text " 'Are you sure you want to leave this page? You will lose any unsaved data.' " so it can say the same but in my language... how to do it? Please help - thanks

(when i translate it, it doesnt change in the frontend). Thanks in advance guys!

bloodstriker
  • 33
  • 2
  • 10
  • i saw the script from here: http://stackoverflow.com/questions/14843454/are-you-sure-you-want-to-leave-this-page-functions-for-cancel-and-ok – bloodstriker Jan 23 '17 at 17:52
  • The browser should display that in the user's default language, wouldn't it? – Josh Jan 23 '17 at 18:53

2 Answers2

2

unfortunately, changing the message seems to only work in Internet Explorer (see w3schools). I don't think you'll be able to insert blocking code either(such as alert()), as it would be a security breach for the browser).

Boris
  • 1,161
  • 9
  • 20
0

also how to make the function be "on" for all external pages and be disabled for any inside pages like "domain.com -> domain.com/about-us" ?

bloodstriker
  • 33
  • 2
  • 10
  • for links, you could add an onclick="checkExternal(event)". the function checkExternal can then check the pointed url, and act accordingly. for example by calling event.preventDefault() and only redirecting after an `if(confirm("you sure?"))` – Boris Jan 23 '17 at 19:30
  • that's a question in and of itself (see http://stackoverflow.com/questions/22382151/confirm-leave-on-external-links-in-wordpress for example). – Boris Jan 23 '17 at 19:32
  • so just to be clear - i have to type this: or i have to do something else? i know its probably a dumb question but its just a bit over my ability ... :(. thanks in advance for your kind help – bloodstriker Jan 23 '17 at 19:49
  • i saw it and i wrote there , but hmm i am not so good in java and there is a loot of code(not only java) there... so i couldnt figure out how to implement it exactly :(. its really confusing - may be you can give me a pointer or 2 as you give to all the other novices you meet ? Thanks really much in advance for your help. I trully can say that if someone doesnt help me i probably wont figure it out. I spent like a day and a half to try figure it out already and i had verry little progress. :( – bloodstriker Jan 24 '17 at 09:31
  • ok that's going to be longer than a comment. You should really ask a new question, so that we can answer it properly. and maybe link it here so I find it :) – Boris Jan 24 '17 at 12:10
  • http://stackoverflow.com/questions/41814038/how-to-make-the-onbeforeunload-function-be-disabled-for-my-own-pages-and-work here is the link- thanks in advance really :) – bloodstriker Jan 30 '17 at 08:59