locked
how to clear a page after clicking a button using javascript(make the page blank) RRS feed

  • Question

  • User186897 posted

    Hello All 

    i have a javascript function when th page is loaded called function init()...in this it displays an image and many other things happen

    now on clicking a button I want this function init() to disappear I man is there any way I can just undo this function init() on button click...what ever happens after page is loaded should all disappear after clicking a button...in general the page has to b cleared of everything when this button is clicked...how would I do it using javascript?

    Wednesday, December 7, 2016 9:27 AM

All replies

  • User527778624 posted

    Hi,

    I want this function init() to disappear

    You can't delete it but you can stop it's execution by storing and reading a flag bit from cookie/localStorage/sessionStorage.

    and set this flag and store in button click.

    Wednesday, December 7, 2016 9:42 AM
  • User186897 posted

    Can I know an example for this or any links of examples as I am new to javascript so dont know much about it

    Wednesday, December 7, 2016 11:38 AM
  • User-707554951 posted

    Hi Lexi85,

    As raju dasa, I think it is possible to realize that.

    The solution raju dasa provided to stop it's execution similar to my previous reply in the following links:

    https://forums.asp.net/p/2110353/6099155.aspx

    Best regards

    Cathy

    Thursday, December 8, 2016 9:40 AM
  • User-1393433442 posted

    Hi,

    You try this code to clear a page after clicking a button using Javascript

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $("img").remove();
    $("p").remove();
    });
    });
    </script>
    </head>
    <body>
    <img src="http://www.w3schools.com/bootstrap/bird.jpg"> 
    <p>This is a paragraph.</p>
    <p>This is another paragraph.</p>
    <p>Click on submit button clear record</p>
    
    <button>Submit</button>
    
    </body>
    </html>

    Thanks,

    Wednesday, January 18, 2017 1:07 PM