【问题标题】:If html page doesn't have the special links, then give an alert with Javascript如果 html 页面没有特殊链接,则使用 Javascript 发出警报
【发布时间】:2012-11-15 15:17:51
【问题描述】:

javascript 函数必须搜索网页(html 正文)中的特殊链接(版权网址)。
如果它没有找到特殊的url,则必须发出警报。

JavaScript 文件示例:

if () {

//If function find the copyright links, then null - don't make anything
}
else
//If function doesn't find copyright links, then give an alert
alert("Please protect original copyright links.")


html页面示例:

<html>
<head>
<script type='text/javascript' src='http:// ... file.js'></script>
</head>

<body>

  <!-- Start Copyrigt Area -->
  <div id="footer">
    <a href="http://example1.com">example1.com</a>
    <a href="http://example2.com">example2.com</a>
  </div>
  <!-- End Copyrigt Area -->

</body>
</html>



为什么?

我为特殊的博客社区网站制作了一些主题。有时,我们的 主题用户删除或更改页脚区域中的版权链接。

博客社区网站不支持任何动态内容,如php, 我们只能在一个页面中使用 html 和一些特殊的内容标签。

另一方面,这个网站不允许JS托管等。所以,JS 第三方托管服务提供商提供的文件。

我不想加密代码。所以我认为我们检查链接 JavaScript 函数。如果我们的链接被删除或更改,那么用户必须 收到警报。

也许,一些主题用户发现这些 javascript 功能并删除 他们并重新托管代码。但我想他们中的大多数人不会 任何东西。

【问题讨论】:

  • 搜索 DOM 不会阻止他们将 CSS 编辑为 display:none;
  • 静默点击某个 URL,以便您可以联系这些人。删除警报对他们来说是微不足道的,但许多人可能不会关注网络请求。
  • if (document.getElementById('footer') === null) { alert('this "protection" is futile'); }
  • 如果他们可以删除页脚,他们也可以删除您的 Javascript 代码。
  • 这与想要禁用源查看、右键单击等的人没有什么不同。总会有办法绕过它。不要浪费你的时间。

标签: javascript html web


【解决方案1】:

这取决于您如何编写 html。假设页脚元素始终存在:

if (document.getElementById('footer').childNodes.length == 0) {

//If function find the copyright links, then null - don't make anything
}
else
//If function doesn't find copyright links, then give an alert
alert("Please protect original copyright links.")

但请记住,这只是计算您放入的内容。

如果您没有放入版权,而您的页脚不存在,请查看 peehaa 的评论。

不过,应该注意的是,您似乎只是在引用版权区域中的链接。就像说 - 我知道这项措施对安全没有任何作用,但如果您关心,这里是版权所有者的链接。如果这是真的,那就太好了。干得好。如果您确实需要安全措施来保护页面上的内容,这将无法保护任何内容。

【讨论】:

  • 更新是否清除了什么?我不知道如何使它更清晰
  • 这不是我最喜欢的解决方案,但非常感谢您的帮助。
  • 我的也不是,但是乍一看很难说这个函数的目标。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-17
  • 2013-02-19
  • 1970-01-01
  • 2021-10-26
  • 2018-05-04
相关资源
最近更新 更多