iframe 的替代文本
我们为 HTML 中的 img
标记提供了替代文本 alt
属性,当图像不出现时,该文本就会显示。我也尝试使用带有 iframe
的标签。
<iframe src="www.abc.com" alt="Web site is not avaialable">
但是当给出 src=""
时,替代文本不会出现。只是想知道如果没有给出 src ,我是否可以通过任何其他方式实现替代文本?
We have alternate text, alt
attribute, for an img
tag in HTML, which will show up when the image doesn't come up. I tried using the tag with iframe
too.
<iframe src="www.abc.com" alt="Web site is not avaialable">
But the alternate text doesn't come up when src=""
is given. Just wanted to know if I can achieve alternate text in any other way, if the src
is not given ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
由于我的第一次尝试误解了您的问题,所以让我们尝试一下:
这将读取任何没有 src 属性或具有空白值的 src 属性的 iframe 的“alt”标记值,并将 alt 文本写入该 iframe 的正文中。
协助使用 Javascript 或 jQuery 将元素写入子 iframe
Since my first attempt misunderstood your question, let's try this instead:
This will read the "alt" tag value for any iframe with either no src attribute or a src attribute with a blank value, and write the alt text into the body of that iframe.
Assist from Write elements into a child iframe using Javascript or jQuery
虽然不是“最干净”的解决方案,但另一种选择是在 CSS 中使用位置和 z-index 来“隐藏”
iframe
下的空图像。这将为您提供真正替代文本的所有元数据优势,而无需编写任何复杂的脚本。如果您只想将其作为占位符显示,直到
iframe
加载完成,这也很好。While not the "cleanest" solution, another option is to use position and z-index in your CSS to "hide" an empty image under the
iframe
. This will give you all of the meta-data advantages of true alt text without needing to go into any complex scripting.It's also good if you just want it as placeholder to display until the
iframe
is done loading.The <iframe> element doesn't support an alt attribute, but it does support longdesc. Still, the HTML specification does not dictate how browsers handle long description (or alternate) text. The only way to guarantee any specific behavior is to use JavaScript. Here is an untested example using jQuery:
我不知道有什么方法可以以任何直接的方式捕获来自 iframe 的 404 响应,但是您可以使用一些 jQuery 捕获它:
I don't know of a way to trap for 404 responses from an iframe in any kind of straightforward way, however you could trap it with some jQuery:
使用带有替代信息的图像作为包含相关 iframe 的 div 的背景怎么样?
或者,更好的是:
您应该考虑使用带有替代信息的图像作为包含相关 iframe 的 div 的背景。这个,结合一些定位,你就在那里......
想想看,这就是我在 iframe 中的广告未加载的情况下显示备用广告的做法......
What about using an image with your alt info on it as the background of the div containing the iframe in question?
Or, better yet:
You should think about using an image with your alt info on it as the background of the div containing the iframe in question. This, combined with some positioning, you are there...
Come to think of it, it's what I do to display a backup ad in the case of, and in place of, where the one in the iframe did not load...