Answer the question
In order to leave comments, you need to log in
How to do a domain replacement in a link using JavaScript?
Hello everyone, please help me to remake the script a little.
There is this design:
<div class="comics">
<div class="str"><a href="http://comicsonline.ru/1/batman/001/1.png" rel="shadowbox[comix]"><img src="http://comicsonline.ru/1/batman/001/1.png" title="Страница №1"></a></div>
<div class="str"><a href="http://comicsonline.ru/1/batman/001/2.png" rel="shadowbox[comix]"><img src="http://comicsonline.ru/1/batman/001/2.png" title="Страница №2"></a></div>
<div class="str"><a href="http://comicsonline.ru/1/batman/001/3.png" rel="shadowbox[comix]"><img src="http://comicsonline.ru/1/batman/001/3.png" title="Страница №3"></a></div>
<div class="str"><a href="http://comicsonline.ru/1/batman/001/4.png" rel="shadowbox[comix]"><img src="http://comicsonline.ru/1/batman/001/4.png" title="Страница №4"></a></div>
<div class="str"><a href="http://comicsonline.ru/1/batman/001/5.png" rel="shadowbox[comix]"><img src="http://comicsonline.ru/1/batman/001/5.png" title="Страница №5"></a></div>
</div>
<script type="text/javascript">
function func(url) {
if(!url)return;
$('.comics a,.comics img').each(function(){
if(!this.getAttribute('orig-url')){
this.setAttribute('orig-url',(this.src||this.href));
};
if(this.tagName=='IMG'&&this.src.indexOf('comicsonline')!=-1){
this.src=url+this.getAttribute('orig-url');
}else if(this.href.indexOf('comicsonline')!=-1){
this.href=url+this.getAttribute('orig-url');
}
});
};
setTimeout(function(){func('http://site.ru/');},10000);
</script>
http://site.ru/
http://site.ru/http://comicsonline.ru/1/batman/001/1.png
http://site.ru/1/batman/001/1.png
Answer the question
In order to leave comments, you need to log in
Instead of:
You need:
this.src=this.getAttribute('orig-url').replace('http://comicsonline.ru/', url);
(c href similar) Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question