I'm trying to send an object from one html page to another in js.
The Object that i'm trying to send is generated by peer.js mentioned in the below code
The key value pair in the object looks different from normal objects
below is the sample code
Firstpage.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js"></script>
<button onclick="myfunction()">Click me</button>
<script>
function myfunction(){
var peer = new Peer("id", {host: '192.168.1.14', port: 9002}); //peer is object that i'm trying to pass which will be //created while declaring the object
localStorage.setItem("sendingObject", peer); // i have tried here setItem to send it to the other page
url = 'someURl/secondPage.html?name='+ encodeURIComponent(peer);
document.location.href = url;
}
</script>
console.log(peer) is displayed below
{options: {…}, destroyed: false, disconnected: false, open: false, connections: {…}, …}
secondPage.html
<script>
window.onload = function () {
var url = document.location.href,
params = url.split('?')[1].split('&'),
data = {}, tmp;
for (var i = 0, l = params.length; i < l; i++) {
tmp = params[i].split('=');
data[tmp[0]] = tmp[1];
}
name=data.name;
console.log(name);
var localObj = (localStorage.getItem("sendingObject")); // here retrieving from the setItem
console.log(localObj);
}
</script>
For console.log(name) ----> it is printing %5Bobject%20Object%5D
For console.log(localObj) ----> it is printing [object Object]