Tự động thay thế link ảnh die

G

G4M

New Member
Chèn hình ảnh minh họa trong bài viết là một việc không thể thiếu để tăng tính hấp dẫn với người đọc. Tuy nhiên vì một lý do nào đó mà link ảnh bị hỏng làm cho trình duyệt không hiển thị ảnh (khi dùng FireFox) hoặc chỉ hiện một khung ảnh trống rổng kèm theo dấu chéo (IE) và lúc đó bạn và người xem sẽ có cảm giác khó chịu.
Bạn thêm đoạn mã bên dưới vào template dưới </head> nhé:
Code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript">  </script> 
  <script type="text/javascript">
$(document).ready(function(){ 
    $("img").each(function(index) { 
        $(this).error(function() { 
            $(this).unbind("error").attr("src", "http://taive.tv/dis/die.png");


            $(this).unbind();
        }); 
        $(this).attr("src", $(this).attr("src")); 
  });     
}); 
</script>

Thay "taive.tv/dis/die.png" thành link ảnh của bạn.
Demo:
6155a47cd44e76a2704c457ecfd913ba_48517539.ddvieterror.png


Nguồn: DDVIET
 

Facebook Comments

Similar threads

Admin
Replies
0
Views
4K
AdminAdmin is verified member.
Admin
Admin
Replies
0
Views
3K
AdminAdmin is verified member.
Admin
cuongpro9x
Replies
1
Views
1K
vietpro2008
V
Admin
Replies
0
Views
2K
AdminAdmin is verified member.
Admin
Admin
Replies
0
Views
2K
AdminAdmin is verified member.
Admin
Back
Top