トップ/web/js_alt

web/js_alt の変更点


#author("2023-12-23T23:21:08+09:00","default:nemusg.pad","nemusg.pad")
#author("2025-08-25T00:26:18+09:00;2023-12-23T23:21:08+09:00","default:nemusg.pad","nemusg.pad")
* リンク切れ画像に代替画像を表示させる [#i27324e3]

なぜかうまくできない。がメモは残しておく

** 代替画像を表示 [#vf505b6a]

#code_x{{
$(function() {
  $('img').error(function() {
    $(this).attr('src', '/img/notfound.gif');
  });
});
}}

Chrome 対応版?

#code_x{{
$(function() {
  $('img').error(function(){
    setTimeout(function() {
        $(this).attr('src', 'error.png');
    }, 0);
  });
});
}}

- [[リンク切れ画像に代替画像を表示する:http://webdev.bulkitem.com/%E3%83%AA%E3%83%B3%E3%82%AF%E5%88%87%E3%82%8C%E7%94%BB%E5%83%8F%E3%81%AB%E4%BB%A3%E6%9B%BF%E7%94%BB%E5%83%8F%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B]]
- [[読み込みに失敗した画像に代替画像を読み込ませる:http://qiita.com/mohsenreza/items/51965876a2daaf2c6152]]
- [[指定された画像が存在しないときに別の画像に置換する:http://kachibito.net/snippets/use-custom-missing-image-graphics]]
- [[jQueryで画像の読み込みエラー(リンク切れなど)時に代替画像を表示させる方法。:http://blog.dskymd.com/archives/1707]]


** タグを非表示 [#o85ccc3e]

#code_x{{
$(document).ready(function() {
    $('img').error(function() {
		//ファイルが存在しない画像はimgタグ自体を削除
        $(this).remove();
    });
});
}}

- [[jQueryで画像ファイルが存在しない場合にその要素(imgタグ)を非表示・削除してみる:http://www.blinderhidden.com/jquery-img-src-no-file-remove-1049.html]]

#include(parts/feedback,notitle)