Titanium Community Questions & Answer Archive

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

Trying to link button to webpage

I have a button that links to a .js file with the following code:

var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function()

sourcecode = this.responseText;




I would like for the code to open the webpage shown, but it only shows up with a white screen. Titanium shows the html from the webpage. However, no image. So …pretty confused.

— asked July 31st 2010 by Lauren R
  • web
  • webpage
  • website

2 Answers

  • If you take a look at the webpage source you will see that al the images have relative urls.
    Being relative Titanium thinks the image is local and of course displays nothing.

    You will need to regex the html code and add to each image the full url.

    — answered July 31st 2010 by Dan Tamas
  • If I understand correctly, you simply want to show your website on the device when a user clicks the button? You don't need to use the HTTPClient for that, just use a WebView.

    Here's a quick sample code: app.js

    — answered July 31st 2010 by Goran Skledar
    • Or if you want to test it in your .js file, just replace the code you pasted with this:

      win = Titanium.UI.currentWindow();
      webView = Titanium.UI.createWebView({
          url: 'http://www.887fm.org'

      — commented July 31st 2010 by Goran Skledar
    • I attempted just adding it to the button in app.js, and that didn't work. The second option didn't either. I made an html file & linked it. That opens the page but the page is HUGE compared to the size of the iPhone window. Sorry, I am totally new to this. Part of an internship.

      — commented July 31st 2010 by Lauren R
    • Lauren, what exactly didn't work when you tried the code above - what happens? If you have issues with the page content not scaling, try enabling or disabling webView.scalesPageToFit.

      — commented July 31st 2010 by Goran Skledar
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.