smuralisankar
asked on
How does this javascript work? What does it mean?
See this page:
There is a heading:
This is the sub-heading:
This is a landing page for a Google adwords campaign.
We have a script on this page that pulls in the keyword that the user searched (Google adwords API) and populates it in the URL and then takes that KW and makes a change on the page.
For eg:
If someone searches for sysaid and sees/clicks on the ad and gets to the landing page, we see this:
This is the heading:
This is the sub-heading:
This is the code that was written by the developer and is used:
Could someone please explain to me what this code means and how it works?
http://freshservice.com/compare-it-service-desk
There is a heading:
IT SERVICE DESK SOFTWARE
This is the sub-heading:
Why Freshservice is better than other Service Desks
This is a landing page for a Google adwords campaign.
We have a script on this page that pulls in the keyword that the user searched (Google adwords API) and populates it in the URL and then takes that KW and makes a change on the page.
For eg:
If someone searches for sysaid and sees/clicks on the ad and gets to the landing page, we see this:
http://freshservice.com/compare-it-service-desk?kw=sysaid
This is the heading:
SYSAID VS FRESHSERVICE
This is the sub-heading:
Why Freshservice is better than Sysaid
This is the code that was written by the developer and is used:
Could someone please explain to me what this code means and how it works?
<script type="text/javascript">
function getParam ( sname )
{
var params = location.search.substr(location.search.indexOf("?")+1);
var sval = "";
params = params.split("&");
for (var i=0; i<params.length; i++)
{
temp = params[i].split("=");
if ( [temp[0]] == sname ) { sval = temp[1]; }
}
return sval;
}
function process_keyword (sname)
{
var apps = {};
apps["servicenow"]="ServiceNow";
apps["service now"]="ServiceNow";
apps["cherwell"]="Cherwell";
apps["landesk"]="Landesk";
apps["connectwise"]="Connectwise";
apps["sysaid"]="Sysaid";
apps["track it"]="Track-It";
apps["ibm tivoli"]="IBM Tivoli";
apps["ca unicenter"]="CA Unicenter";
apps["frontrange heat"]="FrontRange Heat";
apps["frontrange"]="FrontRange";
apps["servicedesk plus"]="ServiceDesk Plus";
apps["autotask"]="Autotask";
apps["bmc remedy"]="BMC Remedy";
apps["bmc remedyforce"]="BMC RemedyForce";
apps["samanage"]="Samanage";
apps["hp service manager"]="HP Service Manager";
apps["topdesk"]="TopDesk";
apps["dell kace"]="Dell Kace";
apps["dellkace"]="DellKace";
apps["manageengine"]="ManageEngine";
apps["citrix gotoassist"]="Citrix GoToAssist";
apps["jira service desk"]="JIRA Service Desk";
apps["numara footprints"]="Numara Footprints";
apps["zendesk for it"]="Zendesk for IT";
keyword = unescape(getParam(sname));
for (key in apps){
if (keyword.toLowerCase().contains(key)){
return apps[key];
}
}
return "other Service Desks";
}
function set_data(sname){
$('#replace_text').html("Why Freshservice is better than "+process_keyword(sname));
var keyw = process_keyword(sname);
if( keyw == "other Service Desks"){
$('#replace_text1').html("IT SERVICE DESK SOFTWARE");
}
else{
$('#replace_text1').html(process_keyword(sname).toUpperCase()+" Vs FRESHSERVICE");
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not able to take the time to break it down line by line and function by function for you. You'll need to go through it yourself, looking up the various commands on Google as you go. Post new questions here (on EE, not this specific question) if you get stuck.
ASKER
function getParam ( sname )
{
var params = location.search.substr(location.search.indexOf("?")+1);
var sval = "";
params = params.split("&");
for (var i=0; i<params.length; i++)
{
temp = params[i].split("=");
if ( [temp[0]] == sname ) { sval = temp[1]; }
}
return sval;
}
I understand that this function:
location.search.substr
Will return the query parameter as a string.
location.search.indexOf
Not sure what this does. I can't find a good answer.
To be honest, I can't understand the the rest of this snippet.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am not an expert developer but I am trying to understand how this works and make modifications and maybe take this further.
I spent quite a bit of time search online but i only got bits and pieces here and there.
I am interested in learning about this at a deeper level. If I could get a more detailed (step by step) description of how this code works, I would really appreciate it.