本地图像文件的来源,例如从Office Word粘贴到可编辑的div时,浏览器不允许。如何检测此错误消息已被解除?
ERROR
Not allowed to load local resource: file:///C:/Users/me/AppData/Local/Temp/msohtmlclip1/01/clip_image003.jpg
HTML
<img width="403" height="403" src="file:///C:\Users\me\AppData\Local\Temp\msohtmlclip1\01\clip_image003.jpg" v:shapes="Grafik_x0020_2">
答案 0 :(得分:0)
尝试在标签中使用JavaScript,因此您可以使用try catch:
try {
var src = "file:///C:\Users\me\AppData\Local\Temp\msohtmlclip1\01\clip_image003.jpg";
var div = document.getElementById('div');
var img = document.createElement('img');
img.src = src;
img.width = 403;
img.height = 403;
div.appendChild(img);
}
catch(error) {
//If error occurs this code will be run
}
您的新HTML代码(图片添加在div标签之间):
<div id = "div"></div>
<script>
try {
var src = "file:///C:\Users\me\AppData\Local\Temp\msohtmlclip1\01\clip_image003.jpg";
var div = document.getElementById('div');
var img = document.createElement('img');
img.src = src;
img.width = 403;
img.height = 403;
div.appendChild(img);
}
catch(error) {
//If error occurs this code will be run
}
</script>
<noscript>
Please update to a browser that supports JavaScript.
</noscript>