How do i pass data from one HTML page to multiple HTML pages using JavaScript but without using local storage.
-
3It seems incomplete question to me.. "What have you tried ?" will make us understand your requirement better...Rayon– Rayon2016-10-31 09:50:46 +00:00Commented Oct 31, 2016 at 9:50
-
by using Local Storage i had tried, But the task is with out using local storage is there any proceduresaikrishna– saikrishna2016-10-31 09:52:16 +00:00Commented Oct 31, 2016 at 9:52
-
it would be helpful for us to help you if you could show us what have you coded and it's not workingSean W– Sean W2016-10-31 09:53:47 +00:00Commented Oct 31, 2016 at 9:53
-
While I agree the question is incomplete, you could take a look at query strings and hash values.Matthijs– Matthijs2016-10-31 09:54:24 +00:00Commented Oct 31, 2016 at 9:54
-
Besides query strings and hash values as mentioned before, cookies may also be an optionsecelite– secelite2016-10-31 09:56:16 +00:00Commented Oct 31, 2016 at 9:56
4 Answers
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
5 Comments
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
1 Comment
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 ...