-2

Hello I wanted to send data from one html page to another

For eg this is my index.html page

<html>
    <body>
        <script>
            var uname = "karan"; // I want to send this
        </script>
    </body>
</html>

And this is newPage.html:

<html>
    <body>
        <script>
            console.log(uname); // I want the uname form index.html
        </script>
    </body>
</html>

I have already tried declaring a new class in another javascript file but it gives undefined

Is there any way I can do this? Thank you

Karan Gandhi
  • 45
  • 13
  • I believe there is an answer there: [https://stackoverflow.com/questions/36599781/how-to-pass-data-from-one-page-to-another-page-html](https://stackoverflow.com/questions/36599781/how-to-pass-data-from-one-page-to-another-page-html) – Musevarg Aug 30 '19 at 11:05

1 Answers1

2

use session storage like this:

sessionStorage.setItem("uname", "karan");

and retrieve it like this on another page:

console.log(sessionStorage.getItem("uname"));
Sher E Yr
  • 106
  • 6