Changing all links and source attributes in the DOM
Working with hosted merchant payment solutions
If you have ever worked with hosted payment solutions such as SecPay (now PayPoint) and WorldPay you will have dealt with Callback pages which are pages containing server-side code e.g .NET, ASP, PHP etc and located on your webserver but are loaded up and displayed within the payment gateways secure domain.
makeAbs = {
// the domain we want to reference
domain : "http://www.mysite.com",
// the virtual directory containing the file that will be referenced
directory : "/somedomain/subdomain/",
// function to modify the DOM call once page has loaded
ModifyDOM : function(){
// change Anchors
this.ChangeLocation("A","href");
// change CSS Links
this.ChangeLocation("LINK","href");
// change SCRIPT
this.ChangeLocation("SCRIPT","src");
// change IMG
this.ChangeLocation("IMG","src");
},
ChangeLocation : function(tag,att){
var o,n,h,e=document.getElementsByTagName(tag);
for(var i=0,l=e.length;i<l;i++){
o = (att=="href")?e[i].href:e[i].src;
// if current href/src is blank then skip
if(o && o!=""){
// if its a relative link
if(!/^https?:\/\//.test(o)){
// if its just a filename then we need the domain + virtual to create absolute URL otherwise just need our domain
n = ((o.substring(0,1)=="/") ? this.domain : this.domain + this.directory) + o;
// if its an absolute URL make sure the payment servers domain is replaced with our own in case relative links
// have already been associated with the wrong location
}else{
n = o.replace(document.location.protocol + "//" + document.domain,this.domain);
}
// now reset with our new value
if(att=="href"){
e[i].href = n
}else{
e[i].src = n;
}
}
}
}
}Labels: Absolute, HREF, Links, Relative, Secpay, SRC, URI, Worldpay



0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
Links to this post:
Create a Link
<< Home