So I wrote a script. It takes the URL parameters to determine which ads to show on the website. As shown below, you can see what's going on. Variables are stored if ?layout=layout1,2,3 are appended to the URL.
// Parse the URL
function getURLParameter(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
islayout = getURLParameter('layout');
if(islayout == "layout1") {
localStorage.setItem("layoutvalue", 1);
}
if(islayout == "layout2") {
localStorage.setItem("layoutvalue", 2);
}
if(islayout == "layout3") {
localStorage.setItem("layoutvalue", 3);
}
else {
var layoutvalue = 0;
}
Further on throughout the page... I'd then have a code that would use the variables received above to determine which ad codes to execute.
if(localStorage.getItem("layoutvalue") == 1){
Ad Code for 1st set of users
}
if(localStorage.getItem("layoutvalue") == 2){
Ad Code for 2nd Set of users
}
else {
Ad code for all users
}
</script>
So that's all fine and dandy... My issue is now when I get the following format for an ad code as shown below.
<script type="text/javascript" id="adblockid"
src="http://ift.tt/2eJ57Wn;"></script>
How can I use an if statement to control when this script get's executed? because the code for this script is not between the but rather apart of the script tags.
Let me know.
Thanks.
Aucun commentaire:
Enregistrer un commentaire