Last active
September 7, 2023 15:59
-
-
Save RobertCam/d2005e43dadb15f93c9dfb7610ba501c to your computer and use it in GitHub Desktop.
Javascript to change the background of an Unbounce page section based on a "background" URL parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* | |
Unbounce Community :: Tips & Scripts :: Dynamically Change Background Image with URL Parameters | |
TS:0002-04-045 | |
*********************** | |
Do not remove this section. It helps our team track useage of external workarounds. | |
*/ | |
function getURLParameter(name) { | |
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null | |
} | |
var background = getURLParameter('background'); | |
if (background) { | |
document.getElementById("lp-pom-block-8").style.backgroundImage = 'url('+background+')'; // add the ID of the section you would like the change the background for | |
}; | |
</script> |
Hi @RobertCam, I really interested on your topic. It work at your webpage, But I failed when implementing it to my website builder (mobirise). Can you give a a similar page, but without tutorial, so I can copy paste all the section code (without filtering) to my website builder. I've tried to copy paste your current tutorial page, but elimated tutorial section is really not an easy task for me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey man, is there anyway I can get this working for images and not just background images?