如果锚文本不匹配,则重定向页面 [英] Redirect The Page if Anchor Text is not Match

查看:117
本文介绍了如果锚文本不匹配,则重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript专家

Javascript Expert,

我是模板开发人员,我在模板底部使用了我的链接作为信用链接.有时人们更改了我的网站链接的锚文本, 而且我想如果有人更改锚文本,那么它应该重定向到example.com

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.com

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>

现在应将其重定向到example.com,因为用户已将锚文本从软区域"更改为梦码"

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

我希望有人给脚本.

推荐答案

也许类似于...

$(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.

还有其他问题.他们可以完全删除该元素.他们可以隐藏它.他们可以将其更改为完全不在屏幕上-1000px的位置.他们可以采用多种方式进行此类验证.

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.

这篇关于如果锚文本不匹配,则重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆