-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>
Sai Krishna
  • 59
  • 2
  • 7

3 Answers3

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>
Shariq Ansari
  • 3,941
  • 1
  • 27
  • 30
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?

Community
  • 1
  • 1
doubleui
  • 516
  • 2
  • 8
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.

Gesha
  • 703
  • 4
  • 7