2014-10-08 58 views
0

我重定向到下载页面(我使用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> 

回答

0

你可以做回一个页面(如果这是最后一页):

history.back(); 

或存储sessionStorage(或localStorage)中的页面URL,并在HTML5 Web存储变量上使用window.location.href()。如果你浏览多个页面。

虽然如果页面download.php是一个完全不同的页面超出你的控制,那么你就没有办法做。一旦你离开一个页面,那个页面上的代码就没有了,你不能在其他页面上做任何事情(如果可能的话,想象一下安全问题)。在这种情况下,您最好的做法是在新标签页中打开下载页面。