iframe的替代文字 [英] Alternate text for iframes

查看:107
本文介绍了iframe的替代文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于HTML中的 img 标记,我们有替代文本 alt 属性,这些标记会在图像不出来。我试着用 iframe 这个标签。

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">

但是当 src =给出。如果没有给出 src

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 ?

推荐答案

由于我第一次尝试误解了你的问题,我们来试试这个:

Since my first attempt misunderstood your question, let's try this instead:

<script>
$(function () {

    $("iframe").not(":has([src])").each(function () {

    var ifrm = this;

    ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;

    ifrm.document.open();
    ifrm.document.write($(this).attr("alt"));
    ifrm.document.close();

    });

});
</script>

这将读取任何iframe的alt标签值,不带任何src属性或src属性与一个空白值,并将alt文本写入该iframe的主体。

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.

来自使用Javascript或jQuery将元素写入子iframe

这篇关于iframe的替代文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆