0

i'm creating that script if someone delete the text or link on footer of my template it will redirect to my site, but its redirecting without removing anything.

function loadBody() {
 var elem = document.getElementById("mycontent");
if(elem.innerHTML !== "MySite" || elem.href !== "http://mysite.com")
  window.location="mysite.com"; 
}

here is the footer html

 <div id='mycontent'>       
  <p>&#169; Template is designed by  <a href='http://mysite.com' title=''>Mysite</a></p>
  </div>

thanks in advance.

user2397942
  • 17
  • 1
  • 7

2 Answers2

2

This doesn't work because of the structure:

function loadBody() {
    var elem = document.getElementById("mycontent");
if(elem.innerHTML !== "MySite" || elem.href !== "http://mysite.com")
    window.location="mysite.com"; 
}

<div id='mycontent'>       
    <p>&#169; Template is designed by  <a href='http://mysite.com' title=''>Mysite</a></p>
</div>

You are assuming thag the a tag has the mycontent id attribute, but it is on the div above it. So, either you change for this:

<div>       
    <p>&#169; Template is designed by  <a id='mycontent' href='http://mysite.com' title=''>Mysite</a></p>
</div>

Or you have to alter the verification on Javascript.

Henrique Barcelos
  • 7,670
  • 1
  • 41
  • 66
1

Did you forget http://? + EDIT: use getAttribute. Updated with the new innerHTML

function loadBody() {
 var elem = document.getElementById("mycontent");
if(elem.innerHTML != "<p>&#169; Template is designed by  <a href='http://mysite.com' title=''>Mysite</a></p>")
  window.location="mysite.com"; 
}
Yotam Omer
  • 15,310
  • 11
  • 62
  • 65