[英]Redirect the page to back if URL changed
My Homepage URL is //localhost:8090 it will run index.html with main.js 我的主页URL为// localhost:8090 ,它将与main.js运行index.html
If the URL is changed to //localhost:8090/icons/sample.png . 如果URL更改为//localhost:8090/icons/sample.png 。 I have to redirect the user to previous page as //localhost:8090 . 我必须将用户重定向为// localhost:8090到上一页。
I tried: 我试过了:
main.js main.js
if(window.location.href.indexOf("icons") > -1)
{
window.history.back();
}
It doesn't work. 没用 The page simply display the image. 该页面仅显示图像。
In modern browsers(IE8+, FF3.6+, Chrome), you can just listen to the hashchange event on window. 在现代浏览器(IE8 +,FF3.6 +,Chrome)中,您只能在窗口上监听hashchange事件。
$(window).bind('hashchange', function() {
window.history.back();
/* things */
});
In some old browsers, you need a timer that continually checks location.hash. 在某些旧的浏览器中,您需要一个计时器来连续检查location.hash。 If you're using jQuery, there is a plugin that does exactly that. 如果您使用的是jQuery,则有一个插件可以完全做到这一点。
function hashHandler(){
this.oldHash = window.location.hash;
this.Check;
var that = this;
var detect = function(){
if(that.oldHash!=window.location.hash){
window.history.back();
}
};
this.Check = setInterval(function(){ detect() }, 100);
}
var hashDetection = new hashHandler();
Do you work on hash change event. 您是否处理哈希更改事件。
Try following: 请尝试以下操作:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
Returns 403 if you access image directly, but allows them to be displayed on site. 如果直接访问图像,则返回403,但允许它们在现场显示。
NOTE: it is possible that when you open some page with image and than copy that image's path into the address bar you can see that image, it is only because of the browser's cache, in fact that image has not been loaded from the server. 注意:打开带有图像的页面并将其路径复制到地址栏中后,您可能会看到该图像,这可能仅是由于浏览器的缓存,实际上该图像尚未从服务器加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.