Search code examples
iosuiwebviewios8url-scheme

window.location.href doesn't work with url scheme


I have a problem in iOS 8 and UIWebView. I'm running an app into webview, in this app I have an icon to call the specific url. This is url that is registered like a application url (url scheme). Then into my UIWebView, when I press the button, other view controller should be shown.

In iOS 7 the button works fine, I tap on it and my other view controller is open. But in iOS 8 when I tap on the button nothing is happening. My method to handle url actions is never called.

The web page is using "window.location.href = MyUrlScheme://...", again this is working perfectly in iOS7, but not in iOS8.

Any ideas?


Solution

  • You've probably found the answer to this question, but I'll leave here my solution, it may help someone. I ran into this problem today, iOS8 UIWebView does not respond to window.location.href = "MyUrlScheme://do-something"...

    So I added an Iframe to the html page, set the src attribute and removed the Iframe.

    var sendObjectMessage = function(parameters) {
        var iframe = document.createElement('iframe');
        iframe.setAttribute('src', "MyUrlScheme://"+parameters);
        document.documentElement.appendChild(iframe);
        iframe.parentNode.removeChild(iframe);
        iframe = null;
    }
    
    sendObjectMessage("send-something");
    

    Take a look at this link https://gist.github.com/irace/3688560