iframe 替代方案
在我问问题之前,我已经经历过这个:iframe 的更好替代品?,还没有找到解决我的问题的方法,或者也许我没有理解正确!
我有一个 HTML 页面,其中左侧包含一个 Dojo 树。当我单击左侧树上的一个元素(例如 element1)时,我会在右侧加载一个带有 url 的 iframe:
www.something.com?selected=element1
现在该框架的源是一个 jsp,它执行以下操作:
<%
/* Get the user selection*/
String selectedElement = request.getParameter("selected");
/* Code to Fetch some content from the database using the above string */
%>
由于左侧树有许多元素,单击每个元素会在右侧加载 iframe,如上所示。这个安排工作得很好。但我想知道这是否是最好的方法?我可以如何不使用 iframe 并仍然获得相同的结果吗?我在某处读到加载 iframe 比不加载 iframe 慢几倍。 任何帮助将不胜感激!
Before I ask my question I have gone through this: Better alternative to an iframe?, and haven't found a solution to my problem, or maybe I did not understand correctly!
I have a HTML-page which contains a Dojo-tree on the left hand side. When I click on an element on the left-hand tree (Say element1), I load an iframe on the right with a url:
www.something.com?selected=element1
Now the source of the frame is a jsp which does this:
<%
/* Get the user selection*/
String selectedElement = request.getParameter("selected");
/* Code to Fetch some content from the database using the above string */
%>
Since the left hand side tree has many elements, clicking on each element loads the iframe on the right hand side as above. The arrangement works perfectly fine. But I am wondering if this is the best way to do it? Can I some how not use iframes and still obtain the same result? I read somewhere that loading iframes is several times slower than not loading iframes.
Any help will be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果链接位于同一域中,您可以使用 jQuery load 来填充 DIV 而不是 iframe。从组织的角度来看,这会更好,并且使有可访问性问题的人更容易浏览您的页面。如果内容来自另一个域,则除非您在服务器上处理请求,否则您将被 iframe 困住。
道场示例
If the links are in the same domain, you could use jQuery load to populate a DIV instead of an iframe. This would be much better from an organizational perspective and make your page much easier to navigate for people with accessibility issues. If the content is from another domain, you're stuck with the iframe unless you process the requests on your server.
Dojo example
使用 iframe 包含来自与父页面相同的服务器的页面片段对于 SEO 和用户体验来说非常糟糕。机器人不会将 iframe 的内容索引为父页面的一部分。 Ctrl+单击或复制应在 iframe 中结束的链接可能会导致“wtf?”最终用户看到结果时的体验。
只需使用服务器端包含,例如
。提供
element1.jsp
等。Ajax 加载也是一种选择,但请不引人注意(即它必须以相同的方式工作)禁用 JS,请参阅 tvanfosson 如何演示)。这样您就可以接触到更广泛的受众并获得更好的搜索引擎优化。
Using iframes to include page fragments which comes from the same server as the parent page is very poor for SEO and user experience. Bots don't index the iframe's content as part of the parent page. Ctrl+Clicking or copying links which should end up in iframe may cause "wtf?" experiences of the enduser when seeing the result.
Just use server side includes like
<jsp:include>
.Provide
element1.jsp
and so on.Ajax-loading is also an option, but please do it unobtrusively (i.e. it must work the same way with JS disabled, see how tvanfosson demonstrated it). This way you reach a wider audience and better SEO.