Alternate Text For Iframes
Solution 2:
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>
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
Solution 3:
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:
// Not tested
$('iframe').each(function() {
if ($(this).attr('href') == '') {
// Do something with $(this).attr('longdesc')
}
});
Solution 4:
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:
<iframeid="myFrame"></iframe><script>
$(function () {
$.ajax({
url: "http://www.abc.com",
success: function (data) {
$("#myFrame").html(data);
},
error: function () {
$("#myFrame").html("Web site is not avaialable");
}
});
</script>
Solution 5:
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...
Post a Comment for "Alternate Text For Iframes"