Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
How Save document.body to variable and load from that variable again

The $("body").load("myUrl") function in jQuery allows the html content of a file to be loaded into the body, in which case all the scripts in the html file in the body are loaded and executed correctly. How to provide html content from a variable to body instead of loading it from a file. For example, consider that:

in index.html:

  <script>
        window.keeper = null;  


        function callForm2() {

            window.keeper = window.document.body;

            $("body").load(
                "Form2.html"
            );

        }


        function closeForm2() {

            window.document.body = window.keeper;

        }
    </script>

in callForm2 Before the body content is called from a file, the current body content stored in a window.keeper variable.

in closeForm2() , I want to take the content from the window.keeper variable (old body content) and set to current body, in which case the content of the variable is not equal to the previously saved one, and I can not return the original content of the variable.

So how do I save the current body content of a variable for the next call? What is the correct way to save and call in this case?

here is my code: (you can also see https://github.com/yarandish/Challenge2)

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I Solved you problem and putting demo here. Your Solution is here: https://github.com/Master2V/FormCallSolution.git

In index.html put this script in head:

    <script>

    window.keeper = null;

    function callForm2() {

        var $body_page = $('body #Page');
        window.keeper = $body_page;
        $body_page.detach();

        $.ajax({
            type: "GET",
            url: "Form2.html",
            data: "",
            dataType: "html",
            success: function (response) {
                $("body").html(response);
            }
        });
    }

    function closeForm2() {

        var $body_page = $('body #Page');
        $body_page.detach();
        
        var $body = $('body');
        $body.append(window.keeper);

    }

</script>

And you must have a div tag with id="Page" in index.html and any other forms that you want to call.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!