jQuery 使用 iframe 替代 html5 中的框架
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18259232/
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
Alternative for frames in html5 using iframes
提问by snekk
I am new to HTML5 and I have done some research and found out that the use of <frameset>
is outdated and from what I read <iframes>
are not. So can someone help me, I want to obtain the same result as the example shown but while using <iframes>
or another substitute for <frameset>
that is not deprecated in HTLM5?
我是 HTML5 的新手,我做了一些研究,发现它的使用<frameset>
已经过时了,而从我读到的内容来看,它并<iframes>
没有。那么有人可以帮助我吗,我想获得与所示示例相同的结果,但是在 HTLM5 中不推荐使用<iframes>
或其他替代<frameset>
品时?
<frameset cols="20%,*,">
<frame src="menu.html">
<frame src="events.html">
</frameset>
回答by drwatsoncode
Frames have been deprecated because they caused trouble for url navigation and hyperlinking, because the url would just take to you the index page (with the frameset) and there was no way to specify what was in each of the frame windows. Today, webpages are often generated by server-side technologies such as PHP, ASP.NET, Ruby etc. So instead of using frames, pages can simply be generated by merging a template with content like this:
框架已被弃用,因为它们给 url 导航和超链接带来了麻烦,因为 url 只会为您提供索引页(带有框架集),并且无法指定每个框架窗口中的内容。今天,网页通常由服务器端技术生成,如 PHP、ASP.NET、Ruby 等。 因此,无需使用框架,页面可以简单地通过将模板与如下内容合并来生成:
Template File
模板文件
<html>
<head>
<title>{insert script variable for title}</title>
</head>
<body>
<div class="menu">
{menu items inserted here by server-side scripting}
</div>
<div class="main-content">
{main content inserted here by server-side scripting}
</div>
</body>
</html>
If you don't have full support for a server-side scripting language, you could also use server-side includes (SSI). This will allow you to do the same thing--i.e. generate a single web page from multiple source documents.
如果您不完全支持服务器端脚本语言,您还可以使用服务器端包含 ( SSI)。这将允许您做同样的事情——即从多个源文档生成一个网页。
But if you really just want to have a section of your webpage be a separate "window" into which you can load other webpages that are not necessarily located on your own server, you will have to use an iframe.
但是,如果您真的只想让网页的一部分成为一个单独的“窗口”,您可以在其中加载不一定位于您自己的服务器上的其他网页,则必须使用iframe。
You could emulate your example like this:
你可以像这样模拟你的例子:
Frames Example
帧示例
<html>
<head>
<title>Frames Test</title>
<style>
.menu {
float:left;
width:20%;
height:80%;
}
.mainContent {
float:left;
width:75%;
height:80%;
}
</style>
</head>
<body>
<iframe class="menu" src="menu.html"></iframe>
<iframe class="mainContent" src="events.html"></iframe>
</body>
</html>
There are probably better ways to achieve the layout. I've used the CSS floatattribute, but you could use tables or other methods as well.
可能有更好的方法来实现布局。我使用了 CSS float属性,但您也可以使用表格或其他方法。
回答by user9371102
HTML 5 does support iframes. There were a few interesting attributes added like "sandbox" and "srcdoc".
HTML 5 确实支持 iframe。添加了一些有趣的属性,例如“沙箱”和“srcdoc”。
http://www.w3schools.com/html5/tag_iframe.asp
http://www.w3schools.com/html5/tag_iframe.asp
or you can use
或者你可以使用
<object data="framed.html" type="text/html"><p>This is the fallback code!</p></object>
回答by user2302019
While I agree with everyone else, if you are dead set on using frames anyway, you can just do index.html in XHTML and then do the contents of the frames in HTML5.
虽然我同意其他人的看法,但如果您无论如何都不想使用框架,那么您可以只在 XHTML 中执行 index.html,然后在 HTML5 中执行框架的内容。