2

I am trying to create a packaged app for Firefox OS which would allow the user to search for a specific content (pictures in this case) from different webpages, and simply see them without having to go into each webpage.

My question is, how can I access (and get data) from an external webpage (like www.google.com for example) using a packaged app (without PHP, just with Javascript, HTML and CSS) ?

PS : What I want is just to reach the text that the webpage provides. For example, if the webpages is only providing a div and a img object with a simple link, I just need that link and nothing more.

aliasbody
  • 816
  • 3
  • 11
  • 25
  • so you want to load a page with js and then parse through it to get the image link? – patrickdamery Sep 16 '14 at 23:11
  • No. I want to get a link which is inside an external webpage and show that image (or just the link) on my own APP (html). – aliasbody Sep 17 '14 at 00:11
  • You could just use an xhr . Look at the Boilerplate app: https://github.com/robnyman/Firefox-OS-Boilerplate-App, specifically https://github.com/robnyman/Firefox-OS-Boilerplate-App/blob/gh-pages/js/webapp.js#l463 you will need to make the app privileged and add the systemxhr permission in the manifest – Jason Weathersby Sep 17 '14 at 15:03
  • do you have control over these external websites? if not, the only way you can get the link that I know of is to actually load the page into js(without displaying to the user) and then parsing through it to get the image link you are looking for. – patrickdamery Sep 17 '14 at 17:52
  • I do not have control over those external websites, I was just hopping to have acces to the HTML and get the img inside it. When you say loading the page into js, what do you mean by that ? Otherwise the "xhr" from Firefox seems to be the best way since it enables cross-domain on Firefox OS. – aliasbody Sep 17 '14 at 20:18
  • @JasonWeathersby: I think it would be useful if you could provide this as an answer. – unor Sep 18 '14 at 08:49

2 Answers2

1

Get the systemxhr permission and make a normal HTTP request through XMLHttpRequest:

var x = new XMLHttpRequest({ mozSystem: true });
x.onload = function() {
  if (x.status === 200) {
    // HTML is now in x.responseText
  }
};
x.open('GET', 'http://www.somerandomwebsite.com');
x.send();

Then process the HTML as needed.

Community
  • 1
  • 1
Jan Jongboom
  • 26,598
  • 9
  • 83
  • 120
  • Thank you for that solution ! I will test it out today and if it worked as expected then I'll select this as the Solution Answer. – aliasbody Sep 26 '14 at 09:25
0

You should check Cordova project which from the version 3.5 provides support for Firefox OS. More info at: https://hacks.mozilla.org/2014/02/building-cordova-apps-for-firefox-os/ and http://cordova.apache.org/

maxxx
  • 657
  • 7
  • 5