Titanium Community Questions & Answer Archive

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

Refresh Webview

My application opens up so that the tab goes to a webview. Below is the code that I have been using to open up the external url however once the program is open, I can't seen to figure out how to get it so that every time the tab is selected, it refreshes the webview

var window = Titanium.UI.currentWindow;

var webview = Titanium.UI.createWebView({url:'http://www.name.com/mobile'});
— asked October 12th 2010 by J W
  • createwebview
  • iphone
  • refresh
  • webview

2 Answers

  • Try this



    — answered October 12th 2010 by John McKnight
    • Changing the code to:


      keeps crashing my application. Any other ideas?

      — commented October 12th 2010 by J W
    • The add method is expecting to receive a control of some type like a view, button, etc. The reload method doesn't return anything, it just refreshes the page so you are essentially sending nothing to add and that causes a crash.

      The lines of code you had in your question were correct, you just need to call webview.reload() when you want to refresh the page in the webview.

      — commented October 12th 2010 by John McKnight
    • If that is the case, is there a way to force the tab to reload the webview everytime it is touched or should I add code to the url the tab is referring to?

      — commented October 12th 2010 by J W
  • The function is webview.reload(), but the trick you need is to call the reload function within an event.

    So, add a listen event that reloads the page when the tab in question gets focus.

    I have it in some code somewhere, so if that doesn't help, let me know and I'll dig it up.

    Peter Janett


    — answered October 13th 2010 by Peter janett
    1 Comment
    • Thanks for your help. I've tried the code below in both my 'News' tab .js page and in app.js but still no luck so if you could tell me where I've gone wrong that would be great.

      tabGroup.addEventListener ('News', function(){(webview.reload)});

      — commented October 13th 2010 by J W
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.