Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Can't open a webView from a web page

Is it possible to create a new webView from a web page (by clicking an anchor tag.) I've been unsuccessful able to do that any help? I'll definitely appreciate

— asked April 6th 2010 by Edison Leon
  • page
  • view
  • web
  • webview
  • windowview
0 Comments

3 Answers

  • Haven't tried this before but something like this might work:

    (in the webview, in a script tag)

    function openPage(url) {
        Ti.App.fireEvent('openPage', url);
        return false;
    }
    

    Then in the webview, in HTML you do something like this to call the function:

    a href="http://www.google.com" onclick="openPage(this.href)"
    

    Back in app.js you have to handle the event by adding an event listener:

    Ti.App.addEventListener('openPage', function(url) {
        // put code here to open a new web view with the url
    });
    

    Good luck and please post your answer if you get it working!

    — answered April 7th 2010 by Jonah Dempcy
    permalink
    0 Comments
  • Beautiful, thank you so much!

    — answered April 7th 2010 by Edison Leon
    permalink
    0 Comments
  • I've tried the above example but can't get it to work. Could you post a working example?

    — answered June 18th 2010 by Jason Calvert
    permalink
    1 Comment
    • This doesn't work for remote webview anymore. The only solution is using xhr to store the remote content then assign the responsetext as html content to the webview.

      — commented June 18th 2010 by Daniel Lim
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.