Wah*_*eed 34 c# asp.net iframe
我正在使用IFrame,从这个IFrame我想重定向到另一个页面.
请告诉我如何在没有任何JavaScript的情况下执行此操作,即不window.location.
Response.Redirect 显示IFrame中的页面,但我想将页面显示为主页面.
o.k*_*k.w 71
如果我们可以使用客户端脚本或用户调用的操作来操纵其他框架/窗口,那将是一种危险.
以下是备选方案列表:
Javascript选项:
window.top.location.href=theLocation;
window.parent.location.href=theLocation;
window.top.location.replace(theLocation);
Run Code Online (Sandbox Code Playgroud)
非JavaScript选项:
<a href="theLocation" target="_top">Click here to continue</a>
<a href="theLocation" target="_parent">Click here to continue</a>
Run Code Online (Sandbox Code Playgroud)
Wah*_*eed 13
我用过这段代码.
ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.parent.location.href = '../CentinelError.aspx'; </script>");
Run Code Online (Sandbox Code Playgroud)
它有效.
好吧,这确实是一个 hack,但是您可以将 Parent-Frame 定义为默认目标:
<base target="_parent">
Run Code Online (Sandbox Code Playgroud)
由于这将适用于 iframe 中的所有链接,因此这可能不是一个令人满意的解决方案 ;-)
小智 5
使用Iframe <>时,我们可以从服务器端和客户端重定向
客户方响应:
window.parent.location.href="http://yoursite.com"
Run Code Online (Sandbox Code Playgroud)
服务器端响应:
Response.Write("<script type=text/javascript> window.parent.location.href ='http://yoursite.com' </script>")
Run Code Online (Sandbox Code Playgroud)