-2

How do i pass data from one HTML page to multiple HTML pages using JavaScript but without using local storage.

Tehc
  • 669
  • 3
  • 10
  • 28
  • 3
    It seems incomplete question to me.. "What have you tried ?" will make us understand your requirement better... – Rayon Oct 31 '16 at 09:50
  • by using Local Storage i had tried, But the task is with out using local storage is there any procedure –  saikrishna Oct 31 '16 at 09:52
  • it would be helpful for us to help you if you could show us what have you coded and it's not working – Sean W Oct 31 '16 at 09:53
  • While I agree the question is incomplete, you could take a look at query strings and hash values. – Matthijs Oct 31 '16 at 09:54
  • Besides query strings and hash values as mentioned before, cookies may also be an option – secelite Oct 31 '16 at 09:56
  • The question is are you trying to pass data on the same domain, just between opened tabs? Like sending data from mysite.com/home to mysite.com/profile (that's where localstorage will be enough), but if you want to transfer data between different domains, you will need to send data as parameters in http request or use external backend service like firebase and connect both websites to the same database. – Dariusz Sikorski Oct 31 '16 at 10:03

4 Answers4

1

Two Ways To Pass Data :

1).Local Storage / Session Storage

2).Cookies.

Cookies Reference Link : http://www.w3schools.com/js/js_cookies.asp

possibly if you want to just transfer data to be used by JavaScript then you can use Hash Tags like this

http://localhost/project/index.html#exist so once when you are done retriving the data show the message and change the window.location.hash to a suitable value.. now whenever you ll refresh the page the hashtag wont be present

NOTE: when you will use this instead ot query strings the data being sent cannot be retrived/read by the server

Rajesh Grandhi
  • 378
  • 3
  • 13
1

you can use url get variables. mypage.html?x=value&y=othervalue.

var url = location.href //gets the current URL
var request = {}; //sets array
var pairs = url.substring(url.indexOf('?') + 1).split('&'); //obtains parameters

for (var i = 0; i < pairs.length; i++) {
    if(pairs[i]) {
        var pair = pairs[i].split('=');
        request[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
     }
}

you now have an array of all the parameters. in this case the array should contain x=value, y=othervalue

if you want to pass data from one page to another you make sure that the url you are navigating to contains the parameters you want the next page to have.

more info: Make a JavaScript array from URL

Community
  • 1
  • 1
Mart
  • 475
  • 4
  • 21
1

I assume that you open a page using JavaScript

window.open("http://www.yourpage.com");

Keep a reference for each window you open

var w = window.open("http://www.yourpage.com");

If you have variable "data" on the page you just opened

w.data = 'your-data-goes-here';
Thum Choon Tat
  • 3,084
  • 1
  • 22
  • 24
0

take a look at :

use cookies : https://stackoverflow.com/questions/3220660/local-storage-vs-cookies

or make rediects with get params :

 window.location = '/fooUrl?fooParam=' + fooValue;

and then you can use : window.location.search to get this value .

see: How to retrieve GET parameters from javascript?

But in my opinion this is really dirty way , if no code we can't do magic , so post your code ...

Community
  • 1
  • 1
Joaquin Javi
  • 880
  • 7
  • 12