繁体   English   中英

从子ajax在父窗口中调用javascript函数

[英]Call javascript function in parent window from child ajax

在一个新站点上工作,并遇到了问题。

我的主页上有一个ajax加载器,它每秒都会加载一个脚本,以检查后台进程是否完成(通常为20秒)

但是,一旦执行了ajax脚本(20秒后),它仍然每秒刷新一次。

ajax脚本完成工作后,我需要将父页面重定向到新的URL。

我的ajax代码:

<script type="text/javascript">
function myFunction()
{
var ajaxRequest;  // The variable that makes Ajax possible!

try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            // Something went wrong
            alert("Your browser broke!");
            return false;
        }
    }
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){

document.getElementById("txtHint").innerHTML=ajaxRequest.responseText;
    }
}
ajaxRequest.open("GET", "code/timer.php?file='.$file.'", true);
ajaxRequest.send(null); 
}
</script>



<script type="text/javascript">
function forward(){

location.href=\'http://domain/newpage.html\';


}

function setTimer(){

set = setInterval( "myFunction()", 1000 );

}
</script>

forward()中的反斜杠; 是因为我的代码是从php回显的。

我已经尝试了一些代码,但是应该工作的主要代码(在子ajax元素中)是:

window.opener.forward();

你们将提供的任何帮助将非常有用...谢谢

开瓶器仅在使用javascript打开的窗口中可用,只需调用

forward();

但是您应该为函数使用另一个名称,这里有一个预定义的方法window.forward()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM