如何阻止对HTML页面的直接访问 [英] How to block direct access to html page

查看:634
本文介绍了如何阻止对HTML页面的直接访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个子html(模板)products.html,我使用JavaScript/jquery函数.load()将它包含在index.html页面中

I have a sub html (template) products.html, that I included in my index.html page with JavaScript/jquery function .load()

现在的问题是,如果您输入products.html的URL,则可以直接访问它,并且它单独提供了一个非常丑陋的页面,因此我尝试使用JS函数windows.location将尝试访问它的任何人重定向到index.html. .这种方法的问题是,当我的模板加载到我的主页中时,js脚本就会触发,并导致刷新到该页面.那么还有另一种方法可以解决这个问题吗?

Now the problem is products.html can be access directly if you type its url, and it gives a very ugly page alone, so I tried to redirect anyone who tries to access it to index.html using JS function windows.location. The problem with this method is, when my template is loaded in my main page, the js script fires, and it leads to refresh to the page. So is there another way to go about this !?

推荐答案

您可以定义类似window.parentPage = true;的变量 在index.html文件中.

You can define a variable like window.parentPage = true; in the index.html file.

在products.html页面中进行如下检查:

In the products.html page make a check like so:

if(!window.parentPage)
{
    window.location.href = "YOUR REDIRECTION PAGE"
}

这篇关于如何阻止对HTML页面的直接访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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