A simple but effective way to show different HTML based on the URL using javascript. This code is stackable which allows multiple variations of content based on the URL.
For example: Surface a differnet header image for emails and QR codes using tracking codes.
if (location.href=='URL1') { document.getElementById('DIV_ID').innerHTML = 'HTML CONTENT'; }
if (location.href=='URL2') { document.getElementById('DIV_ID').innerHTML = 'HTML CONTENT'; } else { document.getElementById('DIV_ID').innerHTML = 'HTML CONTENT'; }
Instructions
- Copy and Paste code above into your webpage. Make sure you add script tags.
- Enter URL's into URL1 and URL2. (do not remove single quotes)
- Enter the ID of the Div area you wish to place HTML. (do not remove single quotes)
- Write HTML variations into the HTML CONTENT spots for URL1, URL2 and else. (do not remove single quotes)
- Save and Preview
This will serve HTML based on the URL1, URL2 or everything else.