You need to sign in to do that
Don't have an account?
PamSalesforce
Site.com display url paramter in custom code
Hi,
I want to dynamically dispay text based on url parameter. I want to fetch the url parameter in custom code element and display text based on url paramater value. The issue is i don't know how to access url paramter in custom code.
Is this even possible?Can someone help me with this?
Thanks. I was not able to get the code to work.
I have used the following and its working fine.
<script>
var a;
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
} ();
</script>
<b><script>document.write(QueryString.name+' '+QueryString.topic);</script></b>
All Answers
HI ,
You can use below function to get URL parameter in custom code
function findQueryParameter( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( decodeURIComponent(window.location.href) );
if( results == null )
return "";
else
return results[1];
}
plz let me know whether it helps you or not.
Thanks. I was not able to get the code to work.
I have used the following and its working fine.
<script>
var a;
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
} ();
</script>
<b><script>document.write(QueryString.name+' '+QueryString.topic);</script></b>