In my view, I am showing an image:
<img src="https://some-host/img1.jpg" onerror="showNoPhotoIcon(this);">
I have defined the function showNoPhotoIcon
in a separate file called common.js
/*========== when image is not available ==========*/
function showNoPhotoIcon(image) {
image.onerror = "";
image.src = '/images/no-photo-icon.jpg'
return true;
}
I am referencing common.js from my view, the following line is at the very bottom of my view (html page)
<script src="/Scripts/app/common.js"></script>
But the function is not accessible from the view, when the image is missing, the code tries to call showNoPhotoIcon
function and I get the following error:
Uncaught ReferenceError: showNoPhotoIcon is not defined
Update1:
After I get the error, I tried to confirm the function is defined or not => it is.
Update2:
This seems to be a timing issue, because sometimes it works and sometimes it does not.