Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Change Product Links - Javascript


PrismaVisual

Question

Site URL: https://mayellre.squarespace.com/rentals

Howdy SQSP forum!

I'm looking for a way to redirect or change the link of my products  on my products page from the automatic product pages they link to, to other individual pages I have already created. I'm using products for the rentals because I will be using them with the "Advanced Map Block" plugin & "Universal Filter" from Michael at squarewebsites. These are not totally integrated yet though.

I've done a lot of reading on the forum and I think it will require javascript?? 😅 Any and all help will be greatly appreciated!

Link to post
  • Answers 4
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Popular Posts

The code you’ve provided above is JavaScript! 😃

🙃 <script> should've given it away huh lol  

4 answers to this question

Recommended Posts

  • 0

After driving myself nuts, turns out no js needed!

For anyone looking for a solution, put this in your code injection

Source

<!-- Custom URL Redirect -->
<script>
   var fromUrl = '/initialURL';
   var toUrl = '/newURL';
   // do not edit below this line
   var fromRegex = "^\\" + fromUrl + "\\/?$";
   var match = location.pathname.match(new RegExp(fromRegex, 'i'));
   if (match && !window.frameElement) {
     window.location.replace(toUrl);
   }
 </script>
<!-- End Of Custom URL Redirect -->
Link to post
  • 0
8 hours ago, PrismaVisual said:

turns out no js needed!

The code you’ve provided above is JavaScript! 😃

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digitalbuilding the features that Squarespace didn't include. Pick dates in any format, show prices in other currencies, take orders without payment or improve your cartI value honesty, integrity, transparency and respect. Links in my posts may refer to SF Digital products or may be affiliate links.  Squarespace. I've been a loyal supporter of the platform since 2007. 

Link to post
  • 0

Hi Guys,

I've been messing around with 2 different approaches since originally posting but haven't been able to work it out (it's been weeks 😑 lol).  I know I'm doing something(s) wrong..I just don't know what I don't know yet! 😅 . I posted this in someone else's thread already but it seems like y'all probably know what you're doing!!!

I'm trying to implement some javascript on my store page so I can redirect the product links. 

I want to redirect product urls like: https://mayellre.squarespace.com/rentals/p/130-water-street to urls like: https://mayellre.squarespace.com/130-water-street.

There are currently 40  rental "products" (more to come eventually), but they will never be able to be added to a cart/purchased. I assume that may be why the first method below doesn't work.

<script>
  window.customCartDrawer = {
onUpdateFunction: function(drawer, data) {
  
$(document).ready(function(){
    $('a').each(function(){
        this.href = this.href.replace('/rentals/p/', '/');
    });

  } }
</script>

 

I was able to get this second option to work for one redirect, however when I tried to implement it for all 40 product links, it only redirects 1 of them. Maybe im targeting them wrong or separating wrong?

Single var set:

<script>
   var fromUrl = '/rentals/p/1-west-street-listing';
   var toUrl = '/1-west-street';
   // do not edit below this line
   var fromRegex = "^\\" + fromUrl + "\\/?$";
   var match = location.pathname.match(new RegExp(fromRegex, 'i'));
   if (match && !window.frameElement) {
     window.location.replace(toUrl);
   }
 </script>

 

My best guess at multiple var (not working) 😕

<script>
var fromUrl = '/rentals/p/1-west-street-listing';
var toUrl = '/1-west-street';

var fromUrl = '/rentals/p/2-gold-street-listing';
var toUrl = '/2-gold-street';

var fromUrl = '/rentals/p/2-water-street-listing';
var toUrl = '/2-water-street';

var fromUrl = '/rentals/p/8-spruce-street-listing';
var toUrl = '/8-spruce-street';

var fromUrl = '/rentals/p/10-barclay-street-listing';
var toUrl = '/10-barclay-street';

var fromUrl = '/rentals/p/10-liberty-street-listing';
var toUrl = '/10-liberty-street';

var fromUrl = '/rentals/p/15-broad-street-listing';
var toUrl = '/15-broad-street';

var fromUrl = '/rentals/p/15-cliff-street-listing';
var toUrl = '/15-cliff-street';

var fromUrl = '/rentals/p/15-park-row-listing';
var toUrl = '/15-park-row';

var fromUrl = '/rentals/p/15-william-street-listing';
var toUrl = '/15-william-street';

var fromUrl = '/rentals/p/19-dutch-street-listing';
var toUrl = '/19-dutch-street';

var fromUrl = '/rentals/p/20-exchange-place-listing';
var toUrl = '/20-exchange-place';

var fromUrl = '/rentals/p/20-pine-street-listing';
var toUrl = '/20-pine-street';

var fromUrl = '/rentals/p/20-west-street-listing';
var toUrl = '/20-west-street';

var fromUrl = '/rentals/p/21-west-street-listing';
var toUrl = '/21-west-street';

var fromUrl = '/rentals/p/21-23-south-william-street-listing';
var toUrl = '/21-23-south-william-street';

var fromUrl = '/rentals/p/30-park-place-listing';
var toUrl = '/30-park-place';

var fromUrl = '/rentals/p/37-wall-street-listing';
var toUrl = '/37-wall-street';

var fromUrl = '/rentals/p/40-broad-street-listing';
var toUrl = '/40-broad-street';

var fromUrl = '/rentals/p/40-broad-street-listing';
var toUrl = '/40-broad-street';

var fromUrl = '/rentals/p/45-wall-street-listing';
var toUrl = '/45-wall-street';

var fromUrl = '/rentals/p/50-west-street-listing';
var toUrl = '/50-west-street';

var fromUrl = '/rentals/p/55-liberty-street-listing';
var toUrl = '/55-liberty-street';

var fromUrl = '/rentals/p/55-wall-street-listing';
var toUrl = '/55-wall-street';

var fromUrl = '/rentals/p/63-wall-street-listing';
var toUrl = '/63-wall-street';

var fromUrl = '/rentals/p/67-wall-street-listing';
var toUrl = '/67-wall-street';

var fromUrl = '/rentals/p/70-pine-street-listing';
var toUrl = '/70-pine-street';

var fromUrl = '/rentals/p/71-broadway-listing';
var toUrl = '/71-broadway';

var fromUrl = '/rentals/p/75-wall-street-listing';
var toUrl = '/75-wall-street';

var fromUrl = '/rentals/p/80-john-street-listing';
var toUrl = '/80-john-street';

var fromUrl = '/rentals/p/85-john-street-listing';
var toUrl = '/85-john-street';

var fromUrl = '/rentals/p/88-greenwich-street-listing';
var toUrl = '/88-greenwich-street';

var fromUrl = '/rentals/p/90-west-street-listing';
var toUrl = '/90-west-street';

var fromUrl = '/rentals/p/90-william-street-listing';
var toUrl = '/90-william-street';

var fromUrl = '/rentals/p/95-wall-street-listing';
var toUrl = '/95-wall-street';

var fromUrl = '/rentals/p/100-barclay-street-listing';
var toUrl = '/100-barclay-street';

var fromUrl = '/rentals/p/110-greenwich-street-listing';
var toUrl = '/110-greenwich-street';

var fromUrl = '/rentals/p/114-liberty-street-listing';
var toUrl = '/114-liberty-street';

var fromUrl = '/rentals/p/123-washington-street-listing';
var toUrl = '/123-washington-street';

var fromUrl = '/rentals/p/130-water-street-listing';
var toUrl = '/130-water-street';

var fromUrl = '/rentals/p/180-water-street-listing';
var toUrl = '/180-water-street';
   // do not edit below this line
   var fromRegex = "^\\" + fromUrl + "\\/?$";
   var match = location.pathname.match(new RegExp(fromRegex, 'i'));
   if (match && !window.frameElement) {
     window.location.replace(toUrl);
   }
 </script>
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...