开发者

iPhone uiWebView - 'didImageWasClicked' like event?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜