Solved

Passing a javascript array of user created objects to another page

Posted on 2006-12-01
2
185 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML problem with Internet Explorer 7 51
How can I write .htaccess code to redirect 301 pages? 1 127
 shows up in Outlook, not OWA or on phone 3 72
Microsoft Edge 9 103
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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 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