<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Customize the contextual menu of UIWebView</title>
	<atom:link href="http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/</link>
	<description>iCab related stuff; Mac, iPhone and Cocoa programming</description>
	<lastBuildDate>Wed, 15 May 2013 09:32:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: Rahaman</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-53210</link>
		<dc:creator>Rahaman</dc:creator>
		<pubDate>Mon, 24 Dec 2012 10:22:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-53210</guid>
		<description><![CDATA[I have created a callback on my uiwebview to trap the longpress gesture, but it is not getting called. I am able to trap the tap/pan gesture but no luck with longpress.. anyone has any idea?

This is my code
    UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self
                                                                                 action:@selector(handleCatapultLongPress:)];
	longGesture.numberOfTapsRequired = 1;
    longGesture.numberOfTouchesRequired = 1;
    longGesture.minimumPressDuration = 0.5;
    longGesture.delegate = self;
    longGesture.allowableMovement = 50;
    
    [self.webView addGestureRecognizer:longGesture];]]></description>
		<content:encoded><![CDATA[<p>I have created a callback on my uiwebview to trap the longpress gesture, but it is not getting called. I am able to trap the tap/pan gesture but no luck with longpress.. anyone has any idea?</p>
<p>This is my code<br />
    UILongPressGestureRecognizer *longGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self<br />
                                                                                 action:@selector(handleCatapultLongPress:)];<br />
	longGesture.numberOfTapsRequired = 1;<br />
    longGesture.numberOfTouchesRequired = 1;<br />
    longGesture.minimumPressDuration = 0.5;<br />
    longGesture.delegate = self;<br />
    longGesture.allowableMovement = 50;</p>
<p>    [self.webView addGestureRecognizer:longGesture];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-37785</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Mon, 15 Oct 2012 09:30:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-37785</guid>
		<description><![CDATA[@Alex
No, I&#039;m sorry, this is not possible. The &quot;same origin policy&quot; of the web engine prevents that a web site from one domain can access the content of another domain. And because the UIWebView API only allows us to hook into the web page through the main document, our injected script always runs in the scope of the main document&#039;s domain, so the content of frames from other domains is not accessible.]]></description>
		<content:encoded><![CDATA[<p>@Alex<br />
No, I&#8217;m sorry, this is not possible. The &#8220;same origin policy&#8221; of the web engine prevents that a web site from one domain can access the content of another domain. And because the UIWebView API only allows us to hook into the web page through the main document, our injected script always runs in the scope of the main document&#8217;s domain, so the content of frames from other domains is not accessible.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-37773</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 15 Oct 2012 06:54:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-37773</guid>
		<description><![CDATA[Hi, Alexander,  Thanks for your post,  There is still a problem to me: Is there anyway to show customise contextual menu for cross-domain iFrame in UIWebView? Thanks.]]></description>
		<content:encoded><![CDATA[<p>Hi, Alexander,  Thanks for your post,  There is still a problem to me: Is there anyway to show customise contextual menu for cross-domain iFrame in UIWebView? Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ML</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-37250</link>
		<dc:creator>ML</dc:creator>
		<pubDate>Sun, 07 Oct 2012 16:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-37250</guid>
		<description><![CDATA[@Alexander

Can&#039;t agree more. This method certainly relies on the fact that the internal view uses UILongPressGestureRecognizer to handle touch events, which can easily change in future releas of iOS. So far it works for for iOS 5 &amp; 6. 

As for removing the targets of existing gesture recognizer by accident, this can be fixed by changing the line to

&lt;pre&gt;
[r removeTarget:self action:@selector(_handleGesture:)];
&lt;/pre&gt;

This removes only the target added by us.]]></description>
		<content:encoded><![CDATA[<p>@Alexander</p>
<p>Can&#8217;t agree more. This method certainly relies on the fact that the internal view uses UILongPressGestureRecognizer to handle touch events, which can easily change in future releas of iOS. So far it works for for iOS 5 &amp; 6. </p>
<p>As for removing the targets of existing gesture recognizer by accident, this can be fixed by changing the line to</p>
<pre>
[r removeTarget:self action:@selector(_handleGesture:)];
</pre>
<p>This removes only the target added by us.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-37241</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sun, 07 Oct 2012 12:09:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-37241</guid>
		<description><![CDATA[@ML
Thanks for your solution.

To hook your own code into the  already existing long press gesture recognizer looks more elegant, that is correct. The only downside is that you&#039;re relying on a certain structure of the private internals (private API) of the UIWebView object.

I haven&#039;t tested it yet, but I&#039;m not sure if your solution can&#039;t mess up anything. Especially when you remove the targets of the existing gesture recognizers of the target view - which can be an internal private sub view within the UIWebView object - you might  break something, because you can not know for what these gesture recognizers are used for. Also it seems that you rely on a long press recognizer that already exists  within the UIWebView, in a private subview of this object. And this can be dangerous, because the internal structure of UIWebView can change any time.]]></description>
		<content:encoded><![CDATA[<p>@ML<br />
Thanks for your solution.</p>
<p>To hook your own code into the  already existing long press gesture recognizer looks more elegant, that is correct. The only downside is that you&#8217;re relying on a certain structure of the private internals (private API) of the UIWebView object.</p>
<p>I haven&#8217;t tested it yet, but I&#8217;m not sure if your solution can&#8217;t mess up anything. Especially when you remove the targets of the existing gesture recognizers of the target view &#8211; which can be an internal private sub view within the UIWebView object &#8211; you might  break something, because you can not know for what these gesture recognizers are used for. Also it seems that you rely on a long press recognizer that already exists  within the UIWebView, in a private subview of this object. And this can be dangerous, because the internal structure of UIWebView can change any time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ML</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-37235</link>
		<dc:creator>ML</dc:creator>
		<pubDate>Sun, 07 Oct 2012 08:58:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-37235</guid>
		<description><![CDATA[Thanks for this great tutorial. I managed to override UIWebView and capture the long press gesture without resorting to overriding UIWindow. I personally think this is a more elegant solution. Here&#039;s my code for your reference. I could only test this on iOS 5 &amp; 6. Would appreciate if someone can test the code on iOS 4. Thanks!

&lt;pre&gt;
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *targetView = [super hitTest:point withEvent:event];

    // remove any previously registered targets
    for (UIGestureRecognizer *r in targetView.gestureRecognizers) {
        [r removeTarget:self action:nil];
    }

    // register with the first UILongPressGestureRecognizer
    for (UIGestureRecognizer *r in targetView.gestureRecognizers) {
        if ([r isKindOfClass:[UILongPressGestureRecognizer class]]) {
            ((UILongPressGestureRecognizer*)r).minimumPressDuration = 0.5; // optional
            [r addTarget:self action:@selector(_handleGesture:)];
            break;
        }
    }
    
    return targetView;
}

- (void)_handleGesture:(UILongPressGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateBegan) {
        CGPoint point = [sender locationInView:self];
        [self _contextualMenuAction:point];
    }
}
&lt;/pre&gt;]]></description>
		<content:encoded><![CDATA[<p>Thanks for this great tutorial. I managed to override UIWebView and capture the long press gesture without resorting to overriding UIWindow. I personally think this is a more elegant solution. Here&#8217;s my code for your reference. I could only test this on iOS 5 &amp; 6. Would appreciate if someone can test the code on iOS 4. Thanks!</p>
<pre>
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *targetView = [super hitTest:point withEvent:event];

    // remove any previously registered targets
    for (UIGestureRecognizer *r in targetView.gestureRecognizers) {
        [r removeTarget:self action:nil];
    }

    // register with the first UILongPressGestureRecognizer
    for (UIGestureRecognizer *r in targetView.gestureRecognizers) {
        if ([r isKindOfClass:[UILongPressGestureRecognizer class]]) {
            ((UILongPressGestureRecognizer*)r).minimumPressDuration = 0.5; // optional
            [r addTarget:self action:@selector(_handleGesture:)];
            break;
        }
    }
    
    return targetView;
}

- (void)_handleGesture:(UILongPressGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateBegan) {
        CGPoint point = [sender locationInView:self];
        [self _contextualMenuAction:point];
    }
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-29652</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Wed, 27 Jun 2012 12:53:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-29652</guid>
		<description><![CDATA[@Lawrence
Only certain elements (like links or images) do have a URL. And accessing this URL is easy, you just need to access the element property whose name is equal to the HTML attribute where this URL is assigned to. So for an image tag the URL of the image is defined in the &quot;src&quot; attribute, so you can access this URL via JS using the following code:
url = imgElement.src

And for links (&quot;a&quot; tag) the HTML attribute is &quot;href&quot;, so you can access the Url this way:

url = aElement.href

This will also resolve relative URLs, so you always get the full URL here, even if the HTML code uses only relative URLs.

Alternatively you can access the values of the attributes this way:

url = element.getAttribute(&quot;href&quot;)

but this will only return the value as it is giving in the HTML code, so a relative URL is not automatically completed to a full URL.]]></description>
		<content:encoded><![CDATA[<p>@Lawrence<br />
Only certain elements (like links or images) do have a URL. And accessing this URL is easy, you just need to access the element property whose name is equal to the HTML attribute where this URL is assigned to. So for an image tag the URL of the image is defined in the &#8220;src&#8221; attribute, so you can access this URL via JS using the following code:<br />
url = imgElement.src</p>
<p>And for links (&#8220;a&#8221; tag) the HTML attribute is &#8220;href&#8221;, so you can access the Url this way:</p>
<p>url = aElement.href</p>
<p>This will also resolve relative URLs, so you always get the full URL here, even if the HTML code uses only relative URLs.</p>
<p>Alternatively you can access the values of the attributes this way:</p>
<p>url = element.getAttribute(&#8220;href&#8221;)</p>
<p>but this will only return the value as it is giving in the HTML code, so a relative URL is not automatically completed to a full URL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lawrence</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-29636</link>
		<dc:creator>Lawrence</dc:creator>
		<pubDate>Wed, 27 Jun 2012 00:41:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-29636</guid>
		<description><![CDATA[@Alexander
Thanks for the post!
After some tweaking I got most of the stuff to work. The problem is that I&#039;m not very familiar with JS and don&#039;t know how to extract the URL from an element. Can you give me a few pointers on this? Thanks in advance!]]></description>
		<content:encoded><![CDATA[<p>@Alexander<br />
Thanks for the post!<br />
After some tweaking I got most of the stuff to work. The problem is that I&#8217;m not very familiar with JS and don&#8217;t know how to extract the URL from an element. Can you give me a few pointers on this? Thanks in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-28484</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Mon, 04 Jun 2012 13:40:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-28484</guid>
		<description><![CDATA[@Eric
The default contextual menu of the iOS will show if &quot;webkitTouchCallout&quot; is not yet set to none for the element.

If this is not working for you, you&#039;re either have done something wrong (typo?), or the document is not a HTML document and doesn&#039;t have a &quot;body&quot; element. In  my code snippets I simply assume that the document is a HTML document with a body element.

For web pages with frames or for XML documents, you need to modify the code so it will
also look into frames etc.]]></description>
		<content:encoded><![CDATA[<p>@Eric<br />
The default contextual menu of the iOS will show if &#8220;webkitTouchCallout&#8221; is not yet set to none for the element.</p>
<p>If this is not working for you, you&#8217;re either have done something wrong (typo?), or the document is not a HTML document and doesn&#8217;t have a &#8220;body&#8221; element. In  my code snippets I simply assume that the document is a HTML document with a body element.</p>
<p>For web pages with frames or for XML documents, you need to modify the code so it will<br />
also look into frames etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-28458</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Mon, 04 Jun 2012 02:06:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-28458</guid>
		<description><![CDATA[Alexander says
@Eric
You need to set the CSS property “-webkit-TouchCallout” to “none” to prevent that the original contextual menu will appear. See the very first code snippet in the blog post. Make sure you set the delegate for the UIWebView correctly, so this code snippet is actually called.
------------------------------------------------------------------------------------------------------------------
I have set the CSS property “-webkit-TouchCallout” to “none” in webViewDidFinishLoad and  the delegate of the UIWebView has called. But it also has happend in ios SDK4.0. BTW ,I want to know if the webView have not finish loading and webViewDidFinishLoad delegate method is not  called,the contextual menu of ios&#039;webView will show?]]></description>
		<content:encoded><![CDATA[<p>Alexander says<br />
@Eric<br />
You need to set the CSS property “-webkit-TouchCallout” to “none” to prevent that the original contextual menu will appear. See the very first code snippet in the blog post. Make sure you set the delegate for the UIWebView correctly, so this code snippet is actually called.<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
I have set the CSS property “-webkit-TouchCallout” to “none” in webViewDidFinishLoad and  the delegate of the UIWebView has called. But it also has happend in ios SDK4.0. BTW ,I want to know if the webView have not finish loading and webViewDidFinishLoad delegate method is not  called,the contextual menu of ios&#8217;webView will show?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-28428</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sun, 03 Jun 2012 12:13:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-28428</guid>
		<description><![CDATA[@julian
Then you&#039;ve probably missed something. Please use the debugger to find out which part of the code is actually called and which is not, to narrow down where you&#039;ve done something wrong. Check the content of variables etc. to find out if they have the expected values.
Also read other blog posts, like for example the following one, which explains a common problem: http://www.icab.de/blog/2011/08/02/adding-javascript-files-as-resources-to-an-xcode-project/]]></description>
		<content:encoded><![CDATA[<p>@julian<br />
Then you&#8217;ve probably missed something. Please use the debugger to find out which part of the code is actually called and which is not, to narrow down where you&#8217;ve done something wrong. Check the content of variables etc. to find out if they have the expected values.<br />
Also read other blog posts, like for example the following one, which explains a common problem: <a href="http://www.icab.de/blog/2011/08/02/adding-javascript-files-as-resources-to-an-xcode-project/" rel="nofollow">http://www.icab.de/blog/2011/08/02/adding-javascript-files-as-resources-to-an-xcode-project/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-28427</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Sun, 03 Jun 2012 12:07:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-28427</guid>
		<description><![CDATA[@Eric
You need to set the CSS property &quot;-webkit-TouchCallout&quot; to &quot;none&quot; to prevent that the original contextual menu will appear. See the very first code snippet in the blog post. Make sure you set the delegate for the UIWebView correctly, so this code snippet is actually called.]]></description>
		<content:encoded><![CDATA[<p>@Eric<br />
You need to set the CSS property &#8220;-webkit-TouchCallout&#8221; to &#8220;none&#8221; to prevent that the original contextual menu will appear. See the very first code snippet in the blog post. Make sure you set the delegate for the UIWebView correctly, so this code snippet is actually called.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: julian</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-28293</link>
		<dc:creator>julian</dc:creator>
		<pubDate>Fri, 01 Jun 2012 06:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-28293</guid>
		<description><![CDATA[Thanx for your tutorial. I Have used for code for opening the contextual menu on the 
m.beemp3.com.  but the problem is that the contextual menu does not appear. Please help me.]]></description>
		<content:encoded><![CDATA[<p>Thanx for your tutorial. I Have used for code for opening the contextual menu on the<br />
m.beemp3.com.  but the problem is that the contextual menu does not appear. Please help me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-28080</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Tue, 29 May 2012 09:17:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-28080</guid>
		<description><![CDATA[Hi Alexander
Thank you,I have successed by your tutorial .But I found that if i commented off the UIActionSheet in the openContextualMenuAt function ,when i hold my finger on a link  for about a second, the webView  also load the link which by my clicked.  I don&#039;t want use the ActionSheet menu ,I want use a new view. I don&#039;t kown what has happened. Any help would be great.Thank you.]]></description>
		<content:encoded><![CDATA[<p>Hi Alexander<br />
Thank you,I have successed by your tutorial .But I found that if i commented off the UIActionSheet in the openContextualMenuAt function ,when i hold my finger on a link  for about a second, the webView  also load the link which by my clicked.  I don&#8217;t want use the ActionSheet menu ,I want use a new view. I don&#8217;t kown what has happened. Any help would be great.Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexander</title>
		<link>http://www.icab.de/blog/2010/07/11/customize-the-contextual-menu-of-uiwebview/comment-page-3/#comment-23870</link>
		<dc:creator>Alexander</dc:creator>
		<pubDate>Wed, 21 Mar 2012 18:50:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.icab.de/blog/?p=159#comment-23870</guid>
		<description><![CDATA[@Daniel
If you define your main window in a XIB file, then you have to change the class of the window object in IB from UIWindow to MyWindow. This can be done in one of the Inspector panels of IB. If you create the window programmatically in your code, you need to create an object of MyWindow instead of one from UIWindow. In case you&#039;re using the new Storyboard, I can&#039;t help you at the moment, I haven&#039;t used Storyboard yet.]]></description>
		<content:encoded><![CDATA[<p>@Daniel<br />
If you define your main window in a XIB file, then you have to change the class of the window object in IB from UIWindow to MyWindow. This can be done in one of the Inspector panels of IB. If you create the window programmatically in your code, you need to create an object of MyWindow instead of one from UIWindow. In case you&#8217;re using the new Storyboard, I can&#8217;t help you at the moment, I haven&#8217;t used Storyboard yet.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
