Trying to link button to webpage

You must Login before you can answer or comment on any questions.

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;

Titanium.API.info(sourcecode);

};

xhr.open("GET","http://www.887fm.org"); xhr.send();

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 3 years ago by Lauren R
0 Comments

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.

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 3 years ago by Goran Skledar
answer permalink
3 Comments
  • 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'
    });
    win.add(webView);

    — commented 3 years ago 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 3 years ago 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 3 years ago by Goran Skledar

Your Answer

Think you can help? Login to answer this question!