我有一个网站,需要和escape按钮,工作起来就像this one (左页)
我尝试查看他们是如何编写代码的,但找不到按钮引用的JavaScript或jQuery文件。
当您单击浮动按钮时,它会将您发送到另一个网站,然后禁用后退按钮并从您的历史记录中删除该网站。
不幸的是,我对如何开始编写这个脚本一无所知。
发布于 2013-12-16 06:40:11
在Chrome开发者控制台中,你可以发现他们的函数叫做escape_page。然后在javascript控制台中键入'escape_page‘,函数如下所示:
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);
}但是,我在他们的网站上没有看到任何许可免责声明,所以不要复制粘贴他们的代码。
发布于 2013-12-16 06:42:23
可以在任何可单击的元素上使用location.replace方法。仅使用javaScript:
<input id="escape_button" type="button" value="escape" onClick="window.location.replace('http://www.google.com')" />来自w3schools
()方法将当前文档替换为新文档。
此方法与assign()的不同之处在于,replace()从文档历史记录中删除当前文档的URL,这意味着不能使用" back“按钮导航回原始文档。
https://stackoverflow.com/questions/20600359
复制相似问题