Possible to open all webview links in new window?
On my iPad app–
I'd like to show some html based content in a part of the screen; but I do not want hyperlinks to load within that containing webview, but instead load inside a webview in a new window that will float above. Is this possible, and if so how would one approach this?
3 Answers
-
Hi Dan,
This would be possible with local HTML, but with HTML loaded from a remote server there would not be a way to do this since the remote page would not be able to communicate with the native wrapper. If you control the HTML being served, you can communicate with the native wrapper using the "local eval" method demonstrated in the Kitchen Sink.
-
Just copied the answer from Pastie to this post ;) (the solution works i have tested it)
Make sure you make a reference to the jQuery library in the header of your HTML. Also remember that you must load the HTML into the WebView from a local file.
This event definition goes in you app.js:
Ti.App.addEventListener('openBrowser',function(e){ Ti.Platform.openURL(e.URL); });
This JQuery goes in the HTML file:
$(document).ready(function(){ $('a').each(function(){ $(this).bind('click',function(){ var theURL=this.getAttribute('href'); var eventObject = new Object; var a = 'URL'; eventObject[a] = theURL; // Fire Titanium Event to Open the URL in a new Window Ti.App.fireEvent('openBrowser',eventObject); return false; }); }) });
-
Hello. So I had to hack this a little bit, but I was able to do it and I'm sharing here.
Opening webView link in new window : Pastie
Another thing that I did, in order to be able to "serve" remote files is that I download the HTML, and then add a <base href> tag, specifying where it is supposed to live. That way I can show a remote HTML file from the local file system, without losing all the internal references it has, such as images and links. Caveat is that the reference to your jQuery library and any other relative reference that YOU need must be converted into an absotute reference, otherwise they will be treated as belonging to the original context of the page.