Redirect The Page if Anchor Text is not Match

2019-09-19 09:26发布

问题:

Javascript Expert,

i am a template developer and i used my link for credit link at the bottom in template. sometime people changed the anchor text of my site link, and i want if someone change the anchor text then it should redirect to example.com

<div id='copyright'>
  <div id='container'>
    <p>Designed by:<a href='http://www.thesofthelp.com'>the soft zone</a> 
     SEO By: <a href='http://www.mojo.com'>mojo</a>
    </p>
    </div>
  </div>

Example Lets suppose someone changed the "The Soft Zone" to "Dream Code" then page should redirect to example.com

<div id='copyright'>
  <div id='container'>
    <p>Designed by:<a href='http://www.thesofthelp.com'>Dream Code</a> 
     SEO By: <a href='http://www.mojo.com'>mojo</a>
    </p>
    </div>
  </div>

Now it should be redirected to example.com because the user changed the anchor text from "The Soft Zone" to "Dream Code"

I hope someone will give the script.

回答1:

Maybe something like...

$(function(){
    var $link = $('#copyright a');

    (function verifyCopyright () {
        if ($link.prop('href') !== 'http://www.thesofthelp.com' || $link.text() !== '**The Soft Zone**') {
            window.location.href = 'http://www.example.com';
        } else {
            setTimeout(verifyCopyright, 1000);
        }
    })();
});

So this would check every second to see if the text of the link changed and if so redirect. The reason I did it this way is if the user put in a script to change it dynamically after a certain period of time, an immediate check would fail.

Here's a concern with this though. If the users are not changing the template dynamically and are instead changing your actual script, what's to stop them from removing this verification? It seems like any solution will be very weak.

There are also other concerns. They could remove the element entirely. They could hide it. They could change it to position absolutely off the screen at -1000px. So many ways they could jack with any kind of verification like this.