2013-12-15 94 views
1

我有一個網站,需要和escape按鈕的工作原理就像this one(左頁)如何創建一個退出按鈕

我嘗試看看他們是如何寫的代碼,但無法找到的JavaScript或按鈕引用的jQuery文件。

當您單擊浮動按鈕時,它會將您發送到其他網站,然後禁用後退按鈕並從歷史記錄中刪除網站。

不幸的是,如何開始寫這個腳本。

+0

潛在的重複:http://stackoverflow.com/questions/22648829/fastest-exit-strategy-for-a-panic-button-in-crisis-abuse-websites – mrwweb

回答

0

在Chrome開發人員控制檯中,您可以發現其功能稱爲escape_page。你鍵入「escape_page」到JavaScript控制檯,功能顯示爲如下:

function escape_page() { 
//here we will first set an array of site withc we can use in the function 
var safeSites = [ 
    "http://google.com", 
    "http://facebook.com", 
    "http://idahostatesman.com", 
    "http://youtube.com", 
    "http://groupon.com", 
    "http://livingsocial.com", 
    "http://cnn.com", 
    "http://twitter.com", 
    "http://yahoo.com", 
    "http://bing.com", 
    "http://digg.com", 
    "http://reddit.com" 
]; 

var randSitesArray = randomizeArray(safeSites); 

var randSite = randSitesArray[Math.floor(Math.random()*safeSites.length)]; 

for (var i = 0; i < randSitesArray.length; i++) { 
    // for each array items fill history 
    //History.pushState(null, "Title", randSitesArray[i]); 
    History.replaceState({state:i}, randSitesArray[i], null); 
    History.pushState({state:i}, randSitesArray[i], null); 
} 
// redirect to one of the websites witht he randomized array 
//alert(randSite); 
window.location.replace(randSite); 
} 

不過,我沒有看到任何許可聲明在他們的網站,所以不要複製粘貼自己的代碼。

+0

謝謝。我從不復制粘貼代碼,我只是看它的靈感。感謝您的發現。 – user3105447

0

您可以在任何可點擊的元素上使用location.replace方法。只需使用JavaScript的:

<input id="escape_button" type="button" value="escape" onClick="window.location.replace('http://www.google.com')" /> 

w3schools

的replace()方法替換爲新的當前文檔。

此方法與assign()之間的區別在於replace()從文檔歷史記錄中刪除當前文檔的URL,這意味着無法使用「返回」按鈕導航回原始文件。

+0

太棒了,謝謝。我會嘗試。 – user3105447

+0

不幸的是,這從來沒有完全跨瀏覽器,仍然提供了Chrome最新的後退按鈕功能,也沒有IE8。請不要使用此功能,並認爲您完全保護了您的用戶。這是一種虛假的安全感。 –