0

I want to pass a boolean type JAVASCRIPT variable value from one html page to another (from page1.html to page2.html). I am not getting idea to do this. I am not sure whether my approach is right or wrong. Please suggest me the correct way to do this.

the value of first_load should change when the page loads for the first time and the changed value is to be sent to another html page.

<html>
  <head>
    <script type="text/javascript">
      first_load = false; 
      function load() {
        first_load = true;
        alert("first_load="+first_load);
        //pass the value of first_load to page2.html
      }
    </script>
  </head>    
  <body onload="load()">    
  </body>
</html>

how can I get the value of first_load at page2.html??

sam
  • 385
  • 3
  • 10
  • 28
  • 1
    I *think* you mis-understood AJAX, basically it's to pass variables to server-side script, like PHP, get it's response and display it dynamically – Alvin Wong Jul 04 '12 at 05:11
  • Yea what exactly are you doing it for? – dano Jul 04 '12 at 05:11
  • Fixed indenting. There's an extra `}` floating around — just saying. – polarblau Jul 04 '12 at 05:17
  • @ alvin wong thanks for the reply. okie then how to pass the value from page1.html to page2.html. I'll edit my post. – sam Jul 04 '12 at 05:18
  • @sam really still don't understand, are you trying to navigate to `page2.html`, and at the same time store a value so that `page2.html` can retrieve it? (and the way you reply comment is wrong [see this](http://stackoverflow.com/editing-help#comment-formatting)) – Alvin Wong Jul 04 '12 at 05:21
  • @alvin thanks for the suggestion and as for your query I just want to pass the value of first_load to another page i.e.page2.html but not to load the page page2.html. – sam Jul 04 '12 at 05:29
  • 1
    @sam unless you are running a server-side script, I don't think it is useful without loading `page2.html`. Perhaps you need to write **more clearly** about what you're trying to do. – Alvin Wong Jul 04 '12 at 05:31

2 Answers2

1

There are several ways to achieve what you trying to do you can use

html5 webstorage

http://www.w3schools.com/html5/html5_webstorage.asp

cookies

http://www.w3schools.com/js/js_cookies.asp

or you can use just a qurystring after all a bool value is just true or false

COLD TOLD
  • 13,513
  • 3
  • 35
  • 52
  • can I use **html5 webstorage** because I am creating simple webpage without using html5? – sam Jul 04 '12 at 05:33
  • @sam yes you can it the job of browser to recognize the html5 in your JavaScript and I think most of the current browser support web storage I also think it the most straight forward approach – COLD TOLD Jul 04 '12 at 05:35
0

You can do this through url variables, cookies, or HTML5 Web Storage.

Url Variables:

How to get the value from the GET parameters?

Cookies

http://www.w3schools.com/js/js_cookies.asp

HTML5 Web Storage

http://www.w3schools.com/html5/html5_webstorage.asp

The most transparent to the user and my choice would be cookies.

Community
  • 1
  • 1
iambriansreed
  • 21,935
  • 6
  • 63
  • 79