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

Beacon

Send a beacon to your script. Optionally, also send information.

Digging for an IP Address

While an app's IP address can always be found in the REMOTE_ADDR value, the value might not be the actual destination of the content retrieved from your website.

Simple CSS Rotate

Rotate divs, tables, and even characters. Specify the number of degrees or fraction of a turn, and you're good to go.

Avoid Expired SSL Certificate

Check the expiration date of your domain's SSL certificate

Image Zoom on Hover

Zoom the image with a hover. CSS. No JavaScript.

The INS and DEL Tags

The INS and DEL tags come in mighty handy to display editing marks and to emphasize ideas with HTML markup.

Viewing HTML Source Code

Three ways to view HTML source code.

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-2026 Will Bontrager Software LLC