简体   繁体   English

JavaScript:不从背后的代码调用javascript函数

[英]JavaScript: Not calling javascript function from the code behind

I have made one .aspx page to upload the image file. 我已经制作了一个.aspx页面来上传图像文件。

Page 1 - from there I am opening Page2.aspx using window.open(small size like dialogbox) in js. 第1页-从那里我在js中使用window.open(像对话框这样的小尺寸)打开Page2.aspx。

Then in Page 2 Javascript I have below WindowRefresh() function to refresh Page 1 and close Page 2(once file upload completes). 然后在第2页Javascript中,我在WindowRefresh()函数下方刷新了第1页并关闭了第2页(一旦文件上传完成)。

That is the reason I have used 'window.opener.location.href' to refer Parent Page(Page 1). 这就是我使用“ window.opener.location.href”来引用父页面(页面1)的原因。

In Page 2 I have below Windowrefresh() function to refresh the parent window and it will close the Upload dialog window. 在第2页中,下面有Windowrefresh()函数来刷新父窗口,它将关闭“上载”对话框窗口。

 function Windowrefresh() {
        if (window.navigator.appName == "Netscape") {
            window.opener.location.href = window.opener.location.href;
            window.opener.location.reload(true);
            self.close();
        }
        else if (window.navigator.appName == "Microsoft Internet Explorer") {
            window.opener.location.href = window.opener.location.href;
            window.opener.location.reload(true);
            window.close();
        }
    }

Now, I want to call this function from the code behind of Page 2 when one session variable has some value. 现在,当一个会话变量具有某个值时,我想从第2页后面的代码中调用此函数。

I tried below things. 我尝试了下面的事情。

ClientScript.RegisterStartupScript(this.GetType(), "key", "Windowrefresh();", true);

And, 和,

Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "Windowrefresh()", true);

But it is neither refreshing Page 1 nor Closing Page 2. 但这既不是刷新页面1也不是关闭页面2。

I am not sure what is wrong in this. 我不确定这有什么问题。

do something like this.. I have not tested the code...... In the child window 做这样的事情..我还没有测试代码...在子窗口中

<body onunload="refreshParent();">

function refreshParent() {
  window.opener.location.href = window.opener.location.href;

  if (window.opener.progressWindow)

 {
    window.opener.progressWindow.close()
  }
  window.close();
}

close the child window when you have the session variable...(i dont know asp so cant help you with that syntax) 当您拥有会话变量时,关闭子窗口...(我不知道asp,因此无法帮助您使用该语法)

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

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