Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.opener.location.href适用于IE,但不适用于Chrome或Safari_Javascript_Google Chrome_Safari_Window.opener - Fatal编程技术网

Javascript window.opener.location.href适用于IE,但不适用于Chrome或Safari

Javascript window.opener.location.href适用于IE,但不适用于Chrome或Safari,javascript,google-chrome,safari,window.opener,Javascript,Google Chrome,Safari,Window.opener,我一直在研究这个问题,虽然在各种论坛上有很多关于类似问题的帖子,但没有一个问题或解决方案与我的完全匹配 我有一个应用程序,它已经成功地使用下面的函数在弹出窗口结束后重定向回父窗口。最近,我一直在调查与其他浏览器的兼容性(允许通过iPad使用该系统),发现在使用Safari或Chrome时,该功能存在问题 父页面是一些数据库信息的摘要,用户单击链接打开一个窗口(通过window.open)以查看更详细的数据。完成后,子窗口上有一个链接,用于刷新父窗口上的数据(部分是为了确保返回父窗口时显示正确的数

我一直在研究这个问题,虽然在各种论坛上有很多关于类似问题的帖子,但没有一个问题或解决方案与我的完全匹配

我有一个应用程序,它已经成功地使用下面的函数在弹出窗口结束后重定向回父窗口。最近,我一直在调查与其他浏览器的兼容性(允许通过iPad使用该系统),发现在使用Safari或Chrome时,该功能存在问题

父页面是一些数据库信息的摘要,用户单击链接打开一个窗口(通过window.open)以查看更详细的数据。完成后,子窗口上有一个链接,用于刷新父窗口上的数据(部分是为了确保返回父窗口时显示正确的数据)并关闭子窗口

Safari中的控制台报告“window.opener.location.href”的结果不是函数”。我曾尝试使用上面的以及“window.opener.document.location.href”和“window.opener.window.location.href”(取自网络上提供的其他解决方案),但没有成功

我知道有些人的这个功能工作得很好,而另一些人有这样的问题。我想知道这个具体情况是否有答案

以下是我的功能:

function quicklink(url) {
window.opener.document.location.href(url);
self.close();
}
这在IE7、8和9上从第一天起就起作用,但在Safari(windows或iPad)或Chrome上不起作用


有什么想法吗?

href
是一个属性,而不是一个方法。只需将URL分配给它:

window.opener.document.location.href = url;

这也适用于IE。它也是一个属性,即使它允许您将其用作一种方法。

使用下面的代码来实现所需的结果

家长:

<script language="javascript">

function open_a_window() 
{
    var w = 200;
        var h = 200;
        var left = Number((screen.width/2)-(w/2));
        var tops = Number((screen.height/2)-(h/2));

        window.open("window_to_close.html", '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+tops+', left='+left);

   return false;
}

// opener:
window.onmessage = function (e) {
  if (e.data === 'location') {
    window.location.replace('https://www.google.com');
  }
};

</script>

<input type="button" onclick="return open_a_window();" value="Open New Window/Tab" />

函数打开一个窗口()
{
var w=200;
var h=200;
左侧变量=数量((屏幕宽度/2)-(w/2));
var tops=数量((屏幕高度/2)-(h/2));
window.open(“window_to_close.html”,“toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizeable=no,copyhistory=no,width='+w+',height='+h+',top='+top+',left='+left);
返回false;
}
//开场白:
window.onmessage=函数(e){
如果(例如,数据==‘位置’){
window.location.replace('https://www.google.com');
}
};
弹出窗口:

<!DOCTYPE html>
<html>
<body onload="quitBox('quit');">

<h1>The window closer:</h1>

<input type="button" onclick="return quitBox('quit');" value="Close This Window/Tab" /> 


<script language="javascript">

function quitBox(cmd) 
{      
    if (cmd=='quit')    
    {   
       window.opener.postMessage('location', '*');
       window.open(location, '_self').close();    
    }     
    return false;   
}

</script>

</body>
</html>

窗口关闭器:
函数quitBox(cmd)
{      
如果(cmd=='quit')
{   
window.opener.postMessage('location','*');
window.open(位置“_self”).close();
}     
返回false;
}

如果用户同时关闭了开启器,那么采取一些防御措施可能会有所帮助,例如:
如果(window.opener){window.opener.document.location.href=url;}如果{/*opener关闭了,请处理它*/}
。谢谢Rob。是的,一旦我让函数在没有它的情况下工作,我肯定会这样做。谢谢。啊,是的,我知道这很简单。现在工作。谢谢你,Guffa。@Barbs如果这是正确的答案,你应该接受它。点击大勾号。