Redirect user if a class is removed

Asked

Viewed 61 times

-3

I created a theme and would like if (only if) the credits contained within the class creditos are removed or tampered with by someone, the page will be redirected to my portfolio.

I found many codes, however, this one I chose is giving error, because it redirects even if the link is correct. I mean, if I put Design by <a href='endereço falso... or is exactly the same as the code below, it redirects the customer’s website to my portfolio in the same way.

<div id="creditos">
   <span class='creditos'>Design por <a href='https://meuportfolio.com' target='_blank'>Nome do designer.</a></span>
</div>

<script type='text/javascript'>
   $(document).ready(function() {
      if ($('span.creditos') != 'https://meuportfolio.com') {
         window.location = 'https://meuportfolio.com'
      } else {
         return False;
      }
   });
</script>

How to correct?

  • 1

    If the client removes the credits, it will remove the redirect as well, that’s irrelevant. The only viable solution is to force a license.

  • Indeed, this is irrelevant, as if the customer has the possibility to remove the class creditos consequently he will be able to remove the script. I saw something similar in a post, where the owner created some functions and Apis and hosted on their platform, so when the user imported the script (the code was all overshadowed) could not remove a tag meta html, because it kept checking if it was not changed, if it was changed, it deconstructed html and displayed an error message where it signaled the tag meta was amended! (required to keep it by using the script)

  • Yes, I’m aware of that (and I’m already taking care of the license details too), but still, I’d like to know how to make this code work to do it ALONG with the license.

  • you can apply the same example above..

1 answer

-3


First of all, you should consider that when you make this deal on the client side, it is 100% "burlable". Well, taking that into account, let’s get the solution:

  1. Check that there is no other time that this class is being declared in spam
  2. Check whether you have called the Jquery library

Now let’s fix the code:

 <div id="creditos">
   <span class='creditos'>Design por <a href='https://google.com' target='_blank'>Nome do designer.</a></span>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type='text/javascript'>
   $(document).ready(function() {
        let c = $('span.creditos > a');
        let link = c.attr("href")
        console.log(link)
      if (link != 'https://google.com') {
         window.location = 'https://google.com'
      }
   });
</script>

DEMO

  • Hello, unfortunately she continues redirecting to my page, regardless of whether the link is correct or not :/

  • check out https://jsfiddle.net/tubx4fs2/ I even edited the answer by adding this link! Note that you are not redirecting, because the link is equal: try to change the link and run again, it will redirect!

  • It worked now! Thank you so much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.