2

I'm working with a company that makes iPhone apps, and they are trying to display a webpage in a webview that they control. So all I give them is a url, and they hit it with certain parameters to customize the page that I serve back. (My page might be served in an iFrame or with some other markup that I don't know about.) The problem is that there are links on that webpage that are opening in the webview when the intent is to have those links open in mobile Safari or in another webview. I've tried changing the target of the href tag to _blank, _self, _parent, and _top to no avail.

If it's not clear, I have no control over the app. So I can't try something like [UIApplication openURL:[NSURL URLWithString:myLink]]. I only have control over the contents of the page I'm returning.

Any suggestions?

le noob
  • 93
  • 1
  • 4

1 Answers1

0

To remain within the same webview, you shouldn't use href. Use ontouchstart event instead. Example:

<a ontouchstart="javascript:window.location = '../abc.html';">Click here</a>

A while back, I used the below javascript function, to ensure that my hrefs were converted to the ontouchstart events, only when browsing on the iPad.

function clearLinks()
{
var isiPad = navigator.userAgent.match(/iPad/i) != null;
if(isiPad)
    {
    var obj = document.getElementById('body').getElementsByTagName('a');
    for(var i =0; i<obj.length; i++)
          {
            var url = obj[i].getAttribute('href');
                if(url.indexOf("javascript")==-1)
                {
                obj[i].setAttribute('ontouchstart', "window.location='" + url + "'");
                obj[i].setAttribute('href', 'javascript:function(){return false;}');
                }
            }
     }

}
Anirudh Ramanathan
  • 46,179
  • 22
  • 132
  • 191