Software, your way.
burger menu icon
WillMaster

WillMasterBlog > Content Protection

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Removing Affiliate Data From Browser's URL

Often, affiliate link URLs contain parameter information. It's how the destination page knows which affiliate provided the link that was clicked.

This article is for those of you who use affiliates for at least some of the products you sell.

A link with a parameter can appear to be an affiliate link. There are people who avoid tapping on affiliate links — or resist buying if they realize they were "tricked" into tapping.

Before we continue, let me define something. Most likely, you know what a url parameter is. For those who don't, a parameter is a "?" character and other text appended to a regular URL.

As an illustration, here is a URL without a parameter and one with a parameter.

https://example.com/page.php
https://example.com/page.php?name=Will

What seems not to be widely known is that the parameters can be removed from the URL in the browser's address bar.

This is the code.

<script type="text/javascript">
history.replaceState(null,'',document.URL.replace(/\?.*$/,''));
</script>

Pop that into your web page and browsers arriving with a URL parameter will have the parameter removed after they arrive.

The JavaScript to remove the URL parameter from the browser's address bar won't affect PHP. You see, PHP runs before the page loads. By the time the page is loading, the PHP will have obtained the information it needs from the URL parameter.

If you have JavaScript that also uses the URL parameter (JavaScript and URL Parameters is an example), then put the above parameter-removing JavaScript somewhere below that.

Other than the condition mentioned in the previous paragraph, parameter-removing JavaScript can be placed anywhere on the page. If you are uncertain, put the URL parameter-removing JavaScript at the bottom of the page. Even below the closing </html> code will work.

Now you know how to change the URL in the browser's address bar. It is malleable with JavaScript. It can be changed without reloading the page.

If affiliates link to your product web site, it may comfort potential buyers if they don't see a link that appears to be an affiliate link.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this blog post helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method


All information in WillMaster Blog articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

Recent Articles in the Library

Silent Notes

Once implemented, this system is a nice logger when occurrences of extra-important events on a web page need to be counted.

JavaScript and URL Parameters

A URL parameter in a browser's address bar can be used with JavaScript.

Closer Image

Hover and the image appears to come closer to the surface of the web page.

Database Table Dump

Database Table Dump can be used to view database table information without accessing the domain control panel.

Valid File Name Characters

Most simple printable characters are valid within file names. Some are not.

Image Hue Shift

Shift the hues of an entire image with this CSS rule.

Inspecting HTML Tags

Software to inspect meta and link tags that might have changed after the web page was loaded.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC