Prevent page reload if there is something inside the div

Asked

Viewed 69 times

0

How could I stop the recharge if there was something inside a div? and it would be possible to prevent by making another div appear with the notice confirmation request instead of the alert javascript? I have no idea how I could do this.

  • Can’t stop a page from reloading. What you can do is use localStorage to save certain content and then capture it when the page is loaded.

  • Stop loading cannot because JS will only know the element exists when it is loaded.

  • would not even be able to perform a last function before the next page is loaded?

  • Use the event onbeforeunload.

  • It worked, vlw.

  • Now that I understand rs... I understood "load" instead of "Reload"

Show 1 more comment

1 answer

2


Guys how much recharging I find it hard to block this, the most you can block would be the F5 key but when checking the content of the DIV I can help you.

You can use jQuery with the following code.

 if ($('div').html() !== ""){
    alert('Esta div possui conteudo');
    }
    else{
    alert('sta div possui conteudo');
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.