2013-12-15 95 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。请不要使用此功能,并认为您完全保护了您的用户。这是一种虚假的安全感。 –