我重定向到下载页面(我使用的是window.location()、window.location.href()或replace()),但是在下载之后,它应该会再次返回到同一页面。我尝试使用setTimeout,但徒劳无功。还有一件事,我没有机会用download.php编写重定向。对于这个要求,有什么解决方案吗?先谢谢你...下面是我的示例代码。
<html>
<head>
<meta http-equiv="refresh" content="5; URL=index.php">
<script type="text/javascript" language="JavaScript">
function doSomething(color)
{
//do something nice with params
document.body.style.background = color;
//alert('Hi......');
/*global window */
/*window.location = 'http://all-free-download.com/free-photos/in_love_cosmos_flower_garden_220378_download.html';*/
window.location.href = 'http://all-free-download.com/free-photos/in_love_cosmos_flower_garden_220378_download.html';
/*return false;*/
//header("location:javascript://history.go(-1)");
window.history.back(-1);
window.onload = function() { setTimeout("redirectPage()",3000);
/*return false;*/
window.location.replace("http://google.com");
document.body.style.background = red;
window.setTimeout(redirectPage(), 500);
}
function redirectPage(){
window.location='http://google.com';
}
function download(){
var url = 'http://all-free-download.com/free-photos/in_love_cosmos_flower_garden_220378_download.html';
var htm = '<iframe src="' + url +'" onload="downloadComplete()"></iframe>';
document.getElementById('frameDiv').innerHTML = htm;
}
</script>
</head>
<body>
This page does call a JavaScript function when the page is loaded,
without using the onload() event call.
<script type="text/javascript" language="JavaScript">
doSomething('blue');
</script>
</body>
</html>发布于 2014-10-08 13:18:49
您可以通过执行以下操作返回一页(如果是最后一页):
history.back();或者将页面URL存储在sessionStorage (或localStorage)中,并对HTML5 web存储变量使用window.location.href()。如果您在多个页面中移动。
但是,如果页面download.php是一个完全不在您控制范围内的页面,那么您将无能为力。一旦你离开一个页面,该页面上的代码就消失了,并且你不能在其他页面上做任何事情(如果你可以的话,想象一下安全问题)。在这种情况下,最好是在新标签页中打开下载页面。
https://stackoverflow.com/questions/26249642
复制相似问题