I have the following html in a page:
<div>
<iframe src="http://google.co.in" style="width:200px;height:200px">
</iframe>
<iframe src="http://" style="width:200px;height:200px">
</iframe>
</div>
This page d开发者_如何学Pythonisplays correctly in Firefox:
But in IE (7 & 8), the whole page gets replaced with the following error page:
Even though I agree this behaviour is odd, it may be intended for security purposes. Try about:blank
rather than http://
.
I wouldn't rely on the browser to check the validity of the URL for you if you want consistent behavior across all browsers.
If it's a user-entered url that you need to validate, consider validating it yourself (probably using regular expressions either in the back-end or javascript depending on your app) before loading it into the iframe. That way you can display your own error message on your own terms if they entered an invalid url.
Since the URL is user-defined, you must have a server-side script that is generating that page. So you can easily check for an invalid URL (or at least, a blank one or just http://
) and either not display anything, put the iframe code with no src parameter, or put a default page.
精彩评论