iframes not valid in XHTML Strict

烂漫一生 提交于 2019-12-10 17:48:23

问题


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&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&amp;aq=0&amp;sll=50.923556,-1.394663&amp;sspn=0.006709,0.01929&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Amber,&amp;hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&amp;t=m&amp;ll=50.923178,-1.393676&amp;spn=0.012985,0.027466&amp;z=15&amp;output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&amp;aq=0&amp;sll=50.923556,-1.394663&amp;sspn=0.006709,0.01929&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Amber,&amp;hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&amp;t=m&amp;ll=50.923178,-1.393676&amp;spn=0.012985,0.027466&amp;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


回答1:


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:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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.




回答2:


There exists a dirty trick with Javascript:

function load()
{
    document.getElementById("ramec").innerHTML = '<iframe class="ramec"></iframe>';
}

and:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="yourjshere.js">
</script>
<title></title>
</head>
<body onload="load()">
<div id="ramec">
</div>
</body>
</html>

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).




回答3:


An object tag performs the same function, no hacks required. Just change the "src" attribute to "data" and add type="text/html".

<object width="550" height="500" data="http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Amber,+115+Portswood+Road,+Southampton,+SO17+2FX,+United+Kingdom&amp;aq=0&amp;sll=50.923556,-1.394663&amp;sspn=0.006709,0.01929&amp;vpsrc=6&amp;ie=UTF8&amp;hq=Amber,&amp;hnear=115+Portswood+Rd,+Southampton+SO17+2,+United+Kingdom&amp;t=m&amp;ll=50.923178,-1.393676&amp;spn=0.012985,0.027466&amp;z=15&amp;output=embed" type="text/html"></object>


来源:https://stackoverflow.com/questions/8265528/iframes-not-valid-in-xhtml-strict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!