window.close()在母版页和控制面板中不起作用 [英] window.close() not working inside masterpage and control Panel
问题描述
我有一个.aspx页面,其中我有一个Asp:Button,单击将关闭哪个用户浏览器(Opera)选项卡。谷歌搜索后找到一个解决方案,从后面的代码实现这一点。 (对于Opera)
< asp:Button ID = BTN runat = 服务器 正文 = 关闭窗口 onclick = BTN_Click < span class =code-keyword> / >
我已经把这段代码在Page.Load活动。
BTN.Attributes.Add(onclick,window.close(););
这就是它以HTML格式呈现
< input type = 提交 名称 = BTN value = 关闭窗口 onclick = 窗口。 close(); id = BTN >
这是我的心如预期的那样,用户点击按钮并关闭窗口。请注意下来浏览器是Opera。
现在查看相同的代码,唯一的区别是按钮是继承母版页和内容面板属性,所以在这种情况下它是这样渲染的
< input type = 提交 名称 < span class =code-keyword> = ctl00 $ MainContentPlaceHolder $ BTN < span class =code-attribute> value = 点击我关闭窗口 onclick = WINDO w.close(); id = ctl00_MainContentPlaceHolder_BTN clientidmode = 静态 >
现在用户点击这个但是意外地它只是刷新浏览器窗口并且没有关闭窗口。
我把这些渲染的代码放在这里因为我坚信它是罪魁祸首。如果是这样你能否建议我如何从代码背后实现这一点??
MainContentPlaceHolder
BTN value = 点击我关闭窗口 onclick = window.close(); < span class =code-attribute> id = ctl00_MainContentPlaceHolder_BTN clientidmode = 静态 >
现在用户点击这,但意外地它只是重新shes浏览器窗口并没有关闭窗口。
我把这些渲染的代码放在这里因为我坚信它是罪魁祸首的ID。如果是这样你能告诉我如何从代码背后实现这个吗?
你只能关闭你创建的选项卡/窗口。您无法以编程方式关闭窗口/选项卡。
例如:您可以使用window.open创建一个窗口(
)然后只有你可以使用window.close()
关闭该窗口。
- 艾米
I have a .aspx page in which I have a Asp:Button, clicking on which user browser(Opera) tab will be closed. After googling alot a found a solution to acheive this from code behind. (for Opera)
<asp:Button ID="BTN" runat="server" Text="close the window" onclick="BTN_Click"/>
I have put this code in Page.Load event.
BTN.Attributes.Add("onclick", "window.close();");
This is What it renders in HTML
<input type="submit" name="BTN" value="close the window" onclick="window.close();" id="BTN">
It is working fine as expected, user clicks the button and window is closed. Please note down browser is Opera.
Now look at the same code, the only difference is the button is inheriting Master Page and Content Panel Properties, so in this case it is rendered like this
<input type="submit" name="ctl00$MainContentPlaceHolder$BTN" value="close the window by clicking me" onclick="window.close();" id="ctl00_MainContentPlaceHolder_BTN" clientidmode="static">
Now user clicks on this but unexpectedly it just refreshes the browser window and doesn't close the window.
I have put these rendered codes here because i firmly beleive it is the ID which is the culprit. If it is so Can you please suggest me how to achieve this from code behind??
MainContentPlaceHolder
BTN" value="close the window by clicking me" onclick="window.close();" id="ctl00_MainContentPlaceHolder_BTN" clientidmode="static">
Now user clicks on this but unexpectedly it just refreshes the browser window and doesn't close the window.
I have put these rendered codes here because i firmly beleive it is the ID which is the culprit. If it is so Can you please suggest me how to achieve this from code behind??
You can only close a tab/window which you create. You cannot close a window/tab programmatically.
eg.: You can create a window usingwindow.open(
) then only you can close that window usingwindow.close()
.
--Amy
这篇关于window.close()在母版页和控制面板中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!