2015-04-17 45 views
0

我想从同一窗口中的弹出窗口打开链接,然后关闭弹出窗口。window.location.href在弹出窗口中不起作用

我这这是类似我一直在寻找:open the link from the popup window in an external window and then close the original popup window

我想的是,解决方案及其关闭,我想弹出而不是重定向到指定的URL。

我在这,因为我在loading php page with class in javascript

现在提到我已经使用弹出窗口PHP页面e.g页A,在其上弹出窗口打开correct.php,我有一个按钮。为此,我使用下面的解决方案,它不重定向到url:

<input type="button" value="Search" ONCLICK="window.location.href='https://www.google.co.in/';parent.$.colorbox.close();"> 

什么可能是不打开指定的网址的原因?

回答

1
user_admin.php 
<html><head> 
</head> 
<body onLoad="clickButton()"> 
<script> 
var pop = new Array(); 
function myFunction() { 
pop[0] = window.open("http://user.php"); 
pop[1] = window.close(); 
} 
</script> 
<script> 
function clickButton() 
{ 
document.getElementById('button1').click(); 
} 
</script> 
<input type="button" id="button1" onClick="myFunction()" value="Button 1" /> 
</body> 
</html> 

user.php 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<script> 
function closeBrowser(){ 
    self.close(); 
} 
</script> 
</head> 
<body onLoad="closeBrowser();"> 

<!-- Write your code here --> 
</body> 
</html> 

我希望这会帮助你。尝试一次。

+0

@ user3824319:我有点困惑。你能解释你的答案吗?所以我可以用我的代码来尝试。谢谢。 – kiran

+0

只需创建两个php页面user.php和user_admin.php。复制并粘贴代码。首先运行user_admin.php。它会使用脚本打开user.php。在user.php代码运行后。弹出窗口将关闭。 这是关闭弹出窗口的脚本 –

相关问题