简体   繁体   English

如果未在colorbox / iframe中打开,则阻止访问页面(重定向)

[英]Prevent access to a page (redirect) if it isn't opened in colorbox/iframe

I've got a page that I don't want anyone to be able to access if it isn't being opened in a colorbox. 我有一个页面,如果没有在彩盒中打开,我不希望任何人能够访问。 I'd like to redirect them back to "/dashboard/". 我想将它们重定向回“/ dashboard /”。

To clarify, if the page is accessed directly(not in an iframe/colorbox), redirect, else, load the page. 为了澄清,如果直接访问页面(不在iframe / colorbox中),重定向,否则,加载页面。

You can use javascript to check if the current page is the top page: 您可以使用javascript检查当前页面是否是首页:

if (top == self) {
  top.location = '/dashboard/';
}

But of course javascript can be turned off. 但当然可以关闭javascript。

If you are opening the item in an iframe, this isn't really possible, as the browser will load the iframe just as it would load it if it visited the page directly. 如果您在iframe中打开项目,这实际上是不可能的,因为浏览器将加载iframe,就像它直接访问页面时加载iframe一样。

You could do a nonce type thing, where you generate a number on page load, and pass it as a GET variable to the iframe, which will check to make sure the val passed to it is the same one as stored in the SESSION, if the session one doesn't exist or is different, redirect; 您可以执行一个nonce类型的事情,在页面加载时生成一个数字,并将其作为GET变量传递给iframe,iframe将检查以确保传递给它的val与存储在SESSION中的相同,如果会话一不存在或不同,重定向; if it is the same delete the value from the session and load normally. 如果它是相同的删除会话中的值并正常加载。

I'm not sure how well that would work though; 我不确定它会有多好用; an example of it breaking may be if the user tries to refresh the iframe, it would instead end up embedding the webpage you're on (/dashboard/) into the iframe. 如果用户尝试刷新iframe,它可能会导致将您所在的网页(/ dashboard /)嵌入到iframe中。

So the simple answer is no, without a some complexity and risking breaking people's experience, it isn't possible. 所以简单的答案是否定的,如果没有一些复杂性并且冒着破坏人们经验的风险,那是不可能的。

This is how you can prevent the call in jquery but I cannot see why this is needed, the user can easily just direct to the link, if you really wanted a temp fix then you could check the parent of the link exists 这是你如何阻止jquery中的调用,但我不明白为什么这是需要的,用户可以轻松地直接链接,如果你真的想要一个临时修复,那么你可以检查链接的父级是否存在

$('a').click(function(e){
    if($(e.target).parent('#colourBoxID').length > 0){

       //go to page

    }
    else{

    //redirect
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM