PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, October 15, 2022

[FIXED] How to make a confirm box appear when user closes or refreshes page

 October 15, 2022     css, dom, html, javascript     No comments   

Issue

so I'm making a drawing app. the problem is, when the user accidentally closes or refreshes the page, all the drawings will be lost. So I made a confirmation box that will confirm if the user really wants to close the page.

I have tried like this:

if (window.onbeforeunload == true ) {
confirm("Change are still not saved. Are you sure?")
}

But it doesn't work. Then what is the best solution to solve this problem?


Solution

onbeforeunload is a function which is called when leaving the page. So you have to define it.

window.onbeforeunload = function()
{
    return "Change are still not saved. Are you sure?";
};


Answered By - flappix
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing