Any ideas on why this weird redirect thing would be happening?!

I have scoured the internet for answers to this so I can help the site owner fix it and get them back into rotation on the Gen Lissa webring, but I’ve come up empty.

The problem exists with innerchile.neocities.org. When you click on the previous and next links for the webring, it redirects to https://innerchile.neocities.org/webri.ng/webring/genlissa/next?via=https:// rather than https://webri.ng/webring/genlissa/next?via=https://innerchile.neocities.org.

It works fine if you click the link from the source code or right-click and open the link, but clicking directly causes that error.

I cannot for the life of me figure it out. There doesn’t seem to be anything in their code that would prevent it from opening normally. It’s also only happening on their website. All other member sites (with the correct code) are working just fine.

Any ideas? I feel bad having to exclude them from the ring already!

I noticed that if I disable JavaScript on the website, the link functions correctly.

It looks like there’s a JS click handler attached to the <body> element by http://www.scmplayer.net/script.js and it’s hitting this condition:

} else if (history.pushState) {
  var url = filter(tar.href).replace(filter(destHost), '');
  window.top.scminside = window;
  window.top.history.pushState(null, null, url);
  e.preventDefault();
}

which looks to be grabbing the href attribute and replacing the value of destHost (which is set above this condition to innerchile.neocities.org) with an empty string. Importantly, it also prevents the default behaviour of the click with e.preventDefault();.

So I think there’s an assumption being made by this code that anything clicked where the href contains the value of location.host (innerchile.neocities.org in this case) should be instead handled with JavaScript’s history.pushState.

I believe this can be fixed by making sure that the anchor being clicked has an href that points to the same domain, which could be done by checking that the href points either to a relative URL (href="/somepage") or an absolute URL on the same domain:

// Absolute URL
if (urlString.indexOf('http://') === 0 || urlString.indexOf('https://') === 0) {
  const absoluteURL = new URL(tar.href)
  if (absoluteURL.host === location.host) {
    // Do history.pushState stuff here
  }
// Relative URL
} else {
  // Do history.pushState stuff here
}

Sorry for the wibbly-wobbly explanation, but hope this helps!

2 Likes

Thank you so much! I didn’t even think to look into the SCM Player script, but it makes sense. I’ll let the site owner know!

1 Like