簡體   English   中英

如果URL更改,則將頁面重定向到后退

[英]Redirect the page to back if URL changed

我的主頁URL為// localhost:8090 ,它將與main.js運行index.html

如果URL更改為//localhost:8090/icons/sample.png 我必須將用戶重定向為// localhost:8090到上一頁。

我試過了:

main.js

if(window.location.href.indexOf("icons") > -1) 
 {
     window.history.back();
 }

沒用 該頁面僅顯示圖像。

在現代瀏覽器(IE8 +,FF3.6 +,Chrome)中,您只能在窗口上監聽hashchange事件。

$(window).bind('hashchange', function() {
  window.history.back();
 /* things */
});

在某些舊的瀏覽器中,您需要一個計時器來連續檢查location.hash。 如果您使用的是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();

您是否處理哈希更改事件。

請嘗試以下操作:

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(gif|jpg)$ - [F]

如果直接訪問圖像,則返回403,但允許它們在現場顯示。

注意:打開帶有圖像的頁面並將其路徑復制到地址欄中后,您可能會看到該圖像,這可能僅是由於瀏覽器的緩存,實際上該圖像尚未從服務器加載。

歸功於Ruslan Osipov

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM