Solved

Passing a javascript array of user created objects to another page

Posted on 2006-12-01
2
182 Views
Last Modified: 2010-04-06
Hi, is there a way to pass an array of user created javascript objects from one page to another?

Here is an example :
<script type="text/javascript">

function myobj(){
this.oneattr = 0;
this.arr = new Array();
}

var test_obj = new myobj();
test_obj.oneattr = "Testing1";
test_obj.arr[0]="Testing2";

var to_pass = new Array();
to_pass[0] = tobj;
</script>

I then want to pass the array "to_pass" to another page and have access to the different attributes of the objects contained in "to_pass".
Is this possible?

Thanks
0
Comment
Question by:rocketsbay
2 Comments
 
LVL 5

Accepted Solution

by:
dasmaer earned 125 total points
Comment Utility
you can url encode and decode with escape() and unescape(), you can then append the string to a link or form action.

Try doing:

var query= escape(to_pass);

document.getElementById("someDivTag").innerHTML="<a href='http://someplace.org/page.html?obj='"+query+">link</a>";

And then decoding on the target page using unescape:

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert('Query Variable ' + variable + ' not found');
}

var to_pass = unescape(getQueryVariable(query));

I'm not certain the you can escape an object so you may be forced to serialise it into a list of strings, hopefully this can get you started.
0
 
LVL 41

Expert Comment

by:HonorGod
Comment Utility
If your object isn't too big, you might store it in a cookie.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
The viewer will learn how to count occurrences of each item in an array.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now