-1

Passing of values from one html page to another html page using javascript And below is my code: Fisrt page as html1.html:

<!DOCTYPE html>
  <html>
   <head>
    <script>
       function newDoc() 
       {
       window.location.assign("html2.html");
       }
    </script>
   </head>
      <body>
         <input type="button" value="submit" onclick="newDoc ()">
      </body>
  </html>

And the second html code as html2.html:

<!DOCTYPE html>
  <html>
    <head>
      <script>
        function newDoc()
        {
         window.location.assign("html1.html");
        }
      </script>
     </head>
      <body>
         <input type="button" value="submit" onclick="newDoc ()">
      </body>
    </html>
4
  • Maybe you can try to store values in localStorage Commented Oct 20, 2016 at 9:50
  • 1
    Use some cookies? Commented Oct 20, 2016 at 9:51
  • Why not simply use POST or GET? Commented Oct 20, 2016 at 9:52
  • read docs. w3schools.com/js/js_cookies.asp Commented Oct 20, 2016 at 10:02

3 Answers 3

2

In html we can load other files into one html file using Iframe

    <body>

      <iframe src="html2.html">

      </iframe>

   </body>

We can use jquery function to load the file into some specific div.

     <script> 
       $(function(){
        $('#header').load("header2.html"); 
       });
     </script>
Sign up to request clarification or add additional context in comments.

Comments

0

In javascript, window.location object has a search attribute. So, if your location is http://example.com/html1.html?foo=bar then your window.location.search is ?foo=bar (console.log(window.location)).

How to parse search string: How can I get query string values in JavaScript?

Comments

0

If the variable that you want to pass is important for your application, maybe it will be better to store it in localStorage/sessionStorage or a cookie.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.