Javascript 是否可以使用 <iframe> 指向 .aspx 页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2313108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to use <iframe> to point to an .aspx page?
提问by Carlos Castillo
I'm trying to use an <iframe>to point to an .aspxfile, but when I load it I keep getting an empty frame, no matter what is in the target .aspxnothing gets displayed. Here the html:
我正在尝试使用 an<iframe>指向一个.aspx文件,但是当我加载它时,我一直得到一个空框架,无论目标中是.aspx什么,都没有显示任何内容。这里的html:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is the principal page</div>
<iframe id="myIframe" src="SimpleTarget.aspx" height="100%" width="100%"></iframe>
</form>
</body>
</html>
Then I tried it pointing to an html and it was succesfully rendered in the browser showing the html content. Here the html:
然后我尝试将它指向一个 html,它在浏览器中成功呈现,显示了 html 内容。这里的html:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is the principal page</div>
<iframe id="myIframe" src="HTMLPage1.htm" height="100%" width="100%"></iframe>
</form>
</body>
</html>
So my question is, am I missing something when defining the iframeor is completely impossible to point to an .aspxwith an iframe?
所以我的问题是,在定义iframeor时我是否遗漏了一些东西,或者完全不可能指向.aspxwith an iframe?
In case it is impossible, is there another way to show aspx pages within another html page?
如果不可能,是否有另一种方法可以在另一个 html 页面中显示 aspx 页面?
回答by anthares
It should work with SimpleTarget.aspx just make sure that the relative path is correct and the page is loaded when you hit it with the browser ...
它应该与 SimpleTarget.aspx 一起使用,只需确保相对路径正确,并且在您使用浏览器点击页面时加载页面...
回答by Chase Florell
Is this bit a typo? if not it could be your problem
这是一个错字吗?如果不是,那可能是你的问题
src="SimpleTarget.aspx"height="100%"
should be
应该
src="SimpleTarget.aspx" height="100%"
This is also a typo (but would not break your rendering.
这也是一个错字(但不会破坏您的渲染。
<iframe id="myIframe" src="HTMLPage1.htm" 100%" width="100%">
should be
应该
<iframe id="myIframe" src="HTMLPage1.htm" height="100%" width="100%">
回答by Dale
I found that the following in a Global.asax file stopped iframes opening aspx pages:
我发现 Global.asax 文件中的以下内容阻止了 iframes 打开 aspx 页面:
void Application_BeginRequest(object sender, EventArgs e) {
HttpContext.Current.Response.AddHeader("X-Frame-Options", "DENY");
}
Used to stop cross site scripting but also breaks internal iframes when using aspx pages; removing this "fixed" the problem for me.
用于停止跨站点脚本,但在使用 aspx 页面时也会破坏内部 iframe;删除这个“修复”了我的问题。
回答by womp
A request for an .aspx page is no different from a request for an HTML file. Either your asp page is not rendering properly (possibly a server error?) or else your iframe is not pointing to it correctly.
对 .aspx 页面的请求与对 HTML 文件的请求没有什么不同。要么您的 asp 页面未正确呈现(可能是服务器错误?),要么您的 iframe 未正确指向它。
I do notice that you have a badly formatted src tag for the .aspx page..
我确实注意到您的 .aspx 页面有一个格式错误的 src 标签。
src="SimpleTarget.aspx"height="100%"
should be
应该
src="SimpleTarget.aspx" height="100%"
回答by Symeon Breen
In firefox you can right click in th iframe and get an iframe menu and choose to open the frame in a new tab - this will confirm the actual url being used by the browser for the iframe and as others have stated allow you to ensure the aspx page does render correctly.
在 firefox 中,您可以右键单击 iframe 并获得 iframe 菜单并选择在新选项卡中打开框架 - 这将确认浏览器为 iframe 使用的实际 url,正如其他人所说,允许您确保 aspx页面确实呈现正确。

