Forum Moderators: open
Really hope you can help me out, I'm totally new to JavaScript but think this may be possible using it, so I'm looking for a little help please...!
I'm developing a site that is going to be franchised, each franchisee will get a copy of the site which is dynamically updated by the original master sites database, i've got this working fine except all the images on the master site use relative urls and i need to change this to an absolute url, for example:
Master sites image code:
<img src="assets/images/logo.png"/>
What i need:
<img scr="http://www.example.com/assets/images/logo.png" />
Is it possible to change all image location to the absolute address using JavaScript, if so can anyone point me in the right direction on how to do this.
Thanks in advance!
[edited by: Fotiman at 2:45 pm (utc) on Jan. 4, 2010]
[edit reason] Examplified URLs [/edit]
function replaceSrcs(){
var imgs = document.getElementsByTagName('img');
var url = 'http://www.example.com/';
foreach(imgs as i){
i.src = url + i.src;
}
}
window.onload = function(){ replaceSrcs(); }
Longer answer,
why? why not build it into the site, like in php or something as if they have javascript turned off the images wont show? not sure you want a site that totaly breaks for those without JS
Alan
[edited by: Fotiman at 2:45 pm (utc) on Jan. 4, 2010]
[edit reason] Examplified URLs [/edit]
@trotts1974:
which is dynamically updated by the original master sites database
One of the reasons it's not stored in the DB is because the main site will be using an opensource CMS system that's currenly uses relative url's within the whole of the pages content html so i'm not reallu sure if this is possible.
I've got in touch with the CMS people to see if it's possible to use absolute instead of the relative.
Thanks again.