Jump to content

HELP with showing warning when closing browser?

Go to solution Solved by paul2009,

Recommended Posts

Site URL: https://www.frostwriter.com

Hi!

I have a website where there is a <textarea> tag is being used. It basically allows the user to type in something and download the content as a txt file. I wish to add a feature that shows a dialog box in the browser which asks "Are you sure you wish to close the browser without saving your work"? I want to add this so that the user doesn't lose their content and can be reminded to download it before leaving the page or refreshing the page. I saw some similar questions in stack exchange but neither of them worked on Squarespace.

 

Any kind of help would be really appreciated! Thanks in advance! 

Link to comment

Looks like you have solved this.

1345960804_Screenshot2020-05-19at15_47_04.thumb.png.c3cdcdffa8da465512110e27a67debdc.png

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment
  • 5 months later...

Could you pretty please post the js function? I'm working on accessibility updates and I've come across a point that I don't think I can figure out without this js function. 

"Users must be warned of any timeout that could result in data loss, unless the data is preserved for longer than 20 hours of user inactivity. "

If you can share your solution, that would be greatly appreciated. Also, I rather like frostwriter, so great job with that.

 

Designer and lover of all things.

Link to comment
19 hours ago, cmpnd said:

Could you pretty please post the js function? I'm working on accessibility updates and I've come across a point that I don't think I can figure out without this js function. 

"Users must be warned of any timeout that could result in data loss, unless the data is preserved for longer than 20 hours of user inactivity. "

If you can share your solution, that would be greatly appreciated. Also, I rather like frostwriter, so great job with that.

 

Have you found the code yet?

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
  • Solution
On 11/11/2020 at 7:35 PM, cmpnd said:

Could you pretty please post the js function?

You can do this with the onbeforeunload event. It allows you to display a "Leave site?" confirmation dialog box when the user tries to leave the current page. The message is determined by the browser.

You add use this event by adding the following code to the code injection area, or by adding it to a Code Block on a specific page.

<script>
window.onbeforeunload = function(event) {
  event.returnValue = "Changes that you made may not be saved.";
};
</script>

   If a post helps you, please click a "Like" option below  ↘️

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.