2

When I click on button on my webpage it should redirect me to other page with JavaScript object. I am not able to code for sending java script object with onclick event to other page. Help me in code for sender side page and receiver side page.

Java script object contains array of multiple key value pairs, and I want to send this array to other page.

Example:

data= {  {region: "Maharashtra",sector: "Manufacturing",size: "MSME",year: "2008"}  and many }

I apologize if my question is not clear.

Termininja
  • 6,620
  • 12
  • 48
  • 49
  • You need to take help of any server side language to achieve this. Store it in session and you will able to access in second page – Ish Sep 07 '16 at 07:35
  • This is possible only if you load the second page using `AJAX`..else if second page is being served by server then the server needs to send you the object – Sandeep Nayak Sep 07 '16 at 07:35
  • you have to set object string in cookie using JSON.stringify(data). – Haresh Vidja Sep 07 '16 at 07:35
  • Possible duplicate of [How to pass javascript object from one page to other](http://stackoverflow.com/questions/7709289/how-to-pass-javascript-object-from-one-page-to-other) – Abhijeet Sep 07 '16 at 07:38
  • You can use the ajax POST request to send the data to the server and parse it on the server. Parsing at server depends on what technology you use at the server end. – ajaykumar Sep 07 '16 at 07:38

2 Answers2

1

There are some ways to do this on JS:

  1. Using Cookies
  2. Using QueryString
  3. Using LocalStorage

Note :

Action using above technique only affected on client side only. Except, targeted page sending it into server.

Fadhly Permata
  • 1,686
  • 13
  • 26
1

you don't need java script, enough add params to your <a src=""></a>

for example in html:

<a src="www.something.com/something?region=Maharasta&size=MSME"> Link </a>

or you can add params to your url dynamic for example by jQuery:

var params = { fuu:1680, buu:1050 };
var str = '?' + jQuery.param( params );
$( "#myLink" ).attr('src', $('#myLink").attr('src') + str) 
Bartłomiej Gładys
  • 4,525
  • 1
  • 14
  • 24