Jump to content

HELP with showing warning when closing browser?

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
  • Replies 6
  • Views 1.9k
  • Created
  • Last Reply

Looks like you have solved this.

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

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

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

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
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  ↘️

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.