iframe 在 XHTML Strict 中无效
我正在使用 Google 地图构建一个网站,默认情况下会生成以下代码:
<iframe width="550" height="500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&aq=0&sll=50.923556,-1.394663&sspn=0.006709,0.01929&vpsrc=6&ie=UTF8&hq=Amber,&hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&t=m&ll=50.923178,-1.393676&spn=0.012985,0.027466&z=15&output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?f=q&source=embed&hl=en&geocode=&q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&aq=0&sll=50.923556,-1.394663&sspn=0.006709,0.01929&vpsrc=6&ie=UTF8&hq=Amber,&hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&t=m&ll=50.923178,-1.393676&spn=0.012985,0.027466&z=15" style="color:#0000FF;text-align:left">View Larger Map</a></small>
现在,在检查 XHTML Strict 时会抛出错误,因为它的框架已过时,但我应该使用什么来代替?
感谢您的帮助
I am building a website with a Google Map, which by default generates this code:
<iframe width="550" height="500" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&aq=0&sll=50.923556,-1.394663&sspn=0.006709,0.01929&vpsrc=6&ie=UTF8&hq=Amber,&hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&t=m&ll=50.923178,-1.393676&spn=0.012985,0.027466&z=15&output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?f=q&source=embed&hl=en&geocode=&q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&aq=0&sll=50.923556,-1.394663&sspn=0.006709,0.01929&vpsrc=6&ie=UTF8&hq=Amber,&hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&t=m&ll=50.923178,-1.393676&spn=0.012985,0.027466&z=15" style="color:#0000FF;text-align:left">View Larger Map</a></small>
Now this throws an error when checked for XHTML Strict, as it is Frames which are outdated, but what should I use instead?
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的页面上必须有地图 iframe,最简单的解决方案是将文档类型更改为 XHTML 1.0 Transitional,这样就允许使用 iframe:
但是,如果您开始发现页面呈现有任何差异(请参阅 标准模式与几乎标准模式),并且您更关心网站在网络浏览器中的外观而不是验证您的标记,只需保留 XHTML 1.0 Strict 文档类型即可。浏览器不会仅仅因为页面是无效的 XHTML 而出错;不管怎样,他们都会很好地处理你的 iframe。
If you must have a Maps iframe on your page, the easiest solution is to change your doctype to XHTML 1.0 Transitional instead, which permits the use of iframes:
However if you start to see any differences in page rendering (see standards mode vs almost standards mode), and you're more concerned about how your site looks in web browsers than validating your markup, just keep the XHTML 1.0 Strict doctype. Browsers won't error out simply because a page is invalid XHTML; they'll handle your iframe just fine either way.
Javascript 存在一个肮脏的技巧:
并且:
第一个链接中的文档验证为 XHTML1.0 Strict,尽管它内部使用了 iframe(尝试文档内的链接)。重要的是,将 iframe 放入文档中的 Javascript 是外部的。
我不确定这是否值得所有的努力。也许更改为 HTML4.1 Strict 文档类型会更有帮助(页面的呈现将与 XHTML1.0 Strict 相同)。
There exists a dirty trick with Javascript:
and:
The document in the first link validates as XHTML1.0 Strict, although it uses iframe inside (try the links inside the document). The important part is that Javascript which puts iframe into the document is external.
I'm not sure if it worth all the effort. Maybe changing to HTML4.1 Strict document type would be much more helpful there (the rendering of page would be the same as with XHTML1.0 Strict).
对象标签执行相同的功能,无需修改。只需将“src”属性更改为“data”并添加 type="text/html" 即可。
An object tag performs the same function, no hacks required. Just change the "src" attribute to "data" and add type="text/html".