Jump to content

How to strip URL referrer part from URL? (= Everything after ".....html")


pstein

Recommended Posts

As you know more and more website introduce a page referrer to know from which other page the visitor came from.

Therefore the first page append something like "?utm_source=sfmc&utm_medium=email&utm_campaign=OEM......" to the target URL:

e.g.

http://www.foobar.com/some/path/myproduct/desc.html?utm_source=sfmc&utm_medium=email&utm_campaign=OEM

Assume I derive from within a javascript the current url similar to

var address = document.URL;

How can I strip off everything after the .html beginning with "?" (mostly ?utm_source.....)

.

 

Edited by pstein
Link to comment
Share on other sites

This is one way to do it.

if(location.search) {
  location.href = location.pathname;
}

It causes a page reload, though.

The history API lets you change the URL without reloading, but I've seen it misused a lot, causing websites to not function as expected. https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...