Question

I parse an XML and use different elements from the xml to build some HTML code that I can then show in a UIWebView. One part of the Parsed XML includes pictures with links. I would like to keep the pictures, but lose the links. Normally I could just replace all the ahref tags in the string, but I would like to keep other links not on pictures. Is there anyway I can do this in XCode to only remove the ahref tags from images?

a href="http://treymorgan.net/wp-content/uploads/2012/06/divorce.jpg" img class="alignleft size-full wp-image-4539" title="divorce" src="http://treymorgan.net/wp-content/uploads/2012/06/divorce.jpg" alt="" width="190" height="150"/ /a

Was it helpful?

Solution

You should be able to do this using CSS rather than altering the link itself. Take a look at this article for a suggestion on how to achieve this:-

http://css-tricks.com/pointer-events-current-nav/

Update: Here's a full working example that disables links placed around images on iOS and many desktop browsers. In your example, you should replace the <body> content with your parsed HTML snippet.

<html>
<head>
    <style type='text/css'>
    a > img {
        pointer-events: none;
        cursor: default;
        }
    </style>
</head>
<body>
    <a href='http://www.google.com'>Link to Google</a><br>
    <a href='http://www.google.com'><img src='[image_url.png]'></a>
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top