Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Turning frequently used code into a function


ocon - 2:44 am on Oct 9, 2012 (gmt 0)


I have several lines of code that I reuse in my script that I would like to turn it into a function. Unfortunately one part of the code that changes. Can I still turn it into a function?

Sometimes it's used like this:
if(p.ll||p.m||p.a){
var url = window.location.href.split("?");
var pr = url[1].split(/[&;]/g);
for(var i=0;i<pr.length;i++) if((pr[i].lastIndexOf("ll=", 0)!==-1) || (pr[i].lastIndexOf("m=", 0)!==-1) || (pr[i].lastIndexOf("a=", 0)!==-1)) pr.splice(i, 1);
window.location = (pr.length>0) ? url[0]+"?"+pr.join("&") : url[0];}


Other times it's used like this:
if(p.x){
var url = window.location.href.split("?");
var pr = url[1].split(/[&;]/g);
for(var i=0;i<pr.length;i++) if(pr[i].lastIndexOf("x=", 0)!==-1) pr.splice(i, 1);
window.location = (pr.length>0) ? url[0]+"?"+pr.join("&") : url[0];}


Thread source:: http://www.webmasterworld.com/javascript/4505715.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com