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

File Uploader

This file uploader is complete as one PHP script. No external modules or classes are required. Optional login for private use.

Fun Jumper

This fun jumper is easy to implement. Paste the code into one of your web pages. When you are ready to define your own content, replace the image tag.

The HTML optgroup Tag

The HTML <optgroup> tag allows you to group items in a dropdown list.

Determining Div Location

I generally get the location and dimension numbers of a div with the JavaScript getBoundingClientRect() function. Then access the numbers I need from the function's return value.

Site-wide Login System

A site-wide log-in system that lets pretty much any directory be password protected.

Image Show

With the no-custimizations-required script, it is now relatively easy to show off a series of images on your web page.

A Variables Dump

This PHP function returns details about the variable that is being dumped.

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