Solved

Passing a javascript array of user created objects to another page

Posted on 2006-12-01
2
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
dasmaer earned 125 total points
ID: 18053349
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
ID: 18054121
If your object isn't too big, you might store it in a cookie.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

710 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