背景说明:在UIWebView上会有图片,需要处理图片点击事件(图片放大)。所以添加了JS
window.onload = function(){
function msg(url){
window.location.href="objc://localImage,"+url;
}
var imgs = document.getElementsByTagName("img");
for(i=0; i<imgs.length; i++)
{
imgs[i].onclick = function()
{
var imgUrl = this.src;
msg(imgUrl);
};
}
}
一直在没有问题,一直到Xcode6发布后就一直存在的问题,就是在UIWebView上的这个JS:location.href= 突然就无效了。由于时间的问题,也就没处理,使用Xcode6编译,使用Xcode5打包。但是这次有时间,就一定把它解决掉。
经过反复试验发现问题出在了 objc://localImage 只要不是 “//”就是可以的。
把这个进行修改就可以了。