Hi all,
If someone help me in below issue please-
I’m using session storage to pass value of one variable from one page to another page. Above below code is working in preview mode( data is passes as expected) however this is not working in published live site.
Categories page code:
import wixData from ‘wix-data’ ;
import {session} from ‘wix-storage’ ;
$w.onReady( function () {
$w( “#clothingimage” ).link = “/clothingpage” ;
$w( “#clothingimage” ).target = “_blank” ;
$w( "#clothingimage" ).onClick( (event) => {
session.setItem( "key1" , "cloth" )
} );
Clothing page code:
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import {session} from ‘wix-storage’ ;
import wixData from ‘wix-data’ ;
$w.onReady( function () {
// TODO: write your page related code here…
let value = session.getItem( “key1” ); // “value”
console.log( “Key value:” ,value )
$w( “#text37” ).text = value
$w( “#text38” ).text = value
//session.clear();
});
When user landed to “Clothingpage”, value of “key1” is not passed in Published live site but in Preview mode the value to “key1” is passed and can be seen in text box( text37 & text38).
Many Thanks
Sushant Malviya
If anyone can assist please please?
Live mode often executes slightly different than Preview (which runs inside the Editor). I suspect that the onClick doesn’t get run since the page switches when clicking on the image (#clothingimage). The following code should work:
$w.onReady(function () {
session.setItem("key1", "cloth");
$w("#clothingimage").link = "/clothingpage";
$w("#clothingimage").target = "_blank";
});
Note that this code doesn’t use an onClick() function.
Instead of a session value, you might also try adding a query to the link:
$w("#clothingimage").link = "/clothingpage?value=cloth";
On the clothing page, you can then get the value using wix-location.query
I hope this helps.
Thanks Yisrael !
Yes correctly said , the onClick is not working and above said code is working in the published site but actually my requirement is when user clicks an image( from categories page) it should redirect to clothing page code and within Clothing page , i need to act based on the image selected/clicked on categories page. How can I achieve this if you can suggest please? How to pass data from one page to another that is the main point we need to think upon.
Many Thanks
Sushant Malviya
As I mentioned in my previous post, you can pass a value to another page by adding a query to URL. For example, to send “cloth” to the clothingpage, do this:
$w("#clothingimage").link = "/clothingpage?value=cloth";
On the clothing page, you can then get the value that was passed in the query by using wix-location.query.
Thank you Yisrael for getting back to me.
I have tried the below code but no luck
Categories page code:
$w.onReady( function () {
$w( “#clothingimage” ).link = “/clothingpage&cloth” ;
$w( “#clothingimage” ).target = “_blank” ;
} );
Clothing page code:
import wixLocation from ‘wix-location’ ;
$w.onReady( function () {
// TODO: write your page related code here…
let query = wixLocation.query;
console.log ( “query:” , query)
When user clicks the image( on categories page) , nothing happens and when I navigate to Clothing page I can see query details as below:
Sorry, my mistake. I corrected my post above. The query should be like the below:
$w("#clothingimage").link = "/clothingpage?value=cloth";
Sorry Yisrael , again no luck, Clicking the image is not going to clothing page, I tried this in Published version
@sushantmalviya84 For some reason I kept using an & instead of a ?. The following was tested and works:
$w("#clothingimage").link = "/clothingpage?value=cloth";
@yisrael-wix Does this cause issue here ? I have selected option “None” here and handled via code as i need to pass values to clothing page. if you can advise please.
@yisrael-wix This works fine , Thank you so much !