Created
July 9, 2018 14:03
-
-
Save crova/dd56e2772d595a2d978f01bf7ca91baa to your computer and use it in GitHub Desktop.
trying to replace href
This file contains hidden or 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> | |
$(function () { | |
var terms = { | |
"email": { //set your term name | |
"default": "" //set your default value | |
}, //don't forget commas to separate terms | |
"aff_sub": { | |
"default": "not given" | |
} | |
}; | |
$.each(terms,function (name, settings) { | |
var value = getURLParameter(name); | |
var regex = new RegExp("\\{\\{"+name+"\\}\\}","g"); | |
if (!value || value == "null") { | |
value = settings.default; | |
} | |
$(".elButton:contains('{{"+name+"}}'), .elTextblock:contains('{{"+name+"}}'), .elHeadline:contains('{{"+name+"}}'), .elBullet:contains('{{"+name+"}}')").each(function() { | |
var replaced = $(this).href().replace(regex, value); | |
$(this).href(replaced); | |
}); | |
}); | |
}); | |
</script> |
This file contains hidden or 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> | |
$(function () { | |
var terms = { | |
"email": { //set your term name | |
"default": "" //set your default value | |
}, //don't forget commas to separate terms | |
"aff_sub": { | |
"default": "not given" | |
} | |
}; | |
$.each(terms,function (name, settings) { | |
var value = getURLParameter(name); | |
var regex = new RegExp("\\{\\{"+name+"\\}\\}","g"); | |
if (!value || value == "null") { | |
value = settings.default; | |
} | |
$(".elButton:contains('{{"+name+"}}'), .elTextblock:contains('{{"+name+"}}'), .elHeadline:contains('{{"+name+"}}'), .elBullet:contains('{{"+name+"}}')").each(function() { | |
var replaced = $(this).html().replace(regex, value); | |
$(this).html(replaced); | |
}); | |
$(".elButton:contains('{{"+name+"}}')").each(function() { // this does not work as I thought | |
var replaced = $(this).href().replace(regex, value); | |
$(this).href(replaced); | |
}); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment