开发者

iPhone uiWebView - 'didImageWasClicked' like event?

开发者 https://www.devze.com 2022-12-20 06:13 出处:网络
Newbie Question. I have a UIWebView that I push HTML code into. In the HTML 开发者_JAVA百科code is an image. Is there a way to get informed that image #3 or image with name \'bob\' was touched ? Some

Newbie Question.

I have a UIWebView that I push HTML code into. In the HTML 开发者_JAVA百科code is an image. Is there a way to get informed that image #3 or image with name 'bob' was touched ? Some event like 'didImageWasClickedAndHereIsTheIDOfTheClickedThingy' perhaps?


I don't think there is a good way to do this that is directly supported by UIWebView, but there is a slightly hacky way.

Add JavaScript onclick handlers to your images that do something like this:

function (imgElement) {
    document.location = "http://myapp/didClick/" + imgElement.id;
}

When the user taps the image, a request will me made, which can be intercepted by your app by implementing webView:shouldStartLoadWithRequest:navigationType: on the UIWebView's delegate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号