html - Two-level javascript missing image? -


i trying update webpage has bit of javascript in replace missing image. way works right looks pcp.gif, , if not found displays error message image instead. (just in this thread)

<p align = center><img src = pcp.gif onerror = "this.onerror=null;this.src='!fireseasononly.gif';"> 

what want pcp.png, if not found display pcp.gif , if both not found display error message image. i'm not having luck getting second level work. tried wrapping in if didn't work way hoping.

<p align = center><img src = pcp.png onerror = "if (this.src='pcp.png') {this.onerror=null;this.src='pcp.gif';} else {this.onerror=null;this.src='!fireseasononly.gif';} "> 

the above doesn't work. if png present, displays it. if not, displays gif if present. if both missing, broken image icon, it's not hitting else statement. suggestions?

here's working answer -- thank help, all, floribon!

onerror="this.src=(this.src === location.protocol + '//' + location.host + '/weather/maps/pcp.gif') ? '!fireseasononly.gif' : 'pcp.gif';" 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -