I have a Firefox OS app where I want a link to open outside of the application (the link is to a different site, and opening it in-application would make the application unusable without a force-quite). How do I do that?
Asked
Active
Viewed 621 times
2 Answers
5
Use target="_blank"
on the <a>
tag:
<a href='http://different.site/' target='_blank'>Different site</a>
Actually, if you send an app with external links without it to the Marketplace, it should be rejected. so watch out :)

Ricardo Panaggio
- 643
- 4
- 9
-
What if I don't want to open new windows when it's not a Firefox OS app? :\ – Brendan Long Sep 30 '13 at 14:47
-
Make that up to the build :) When building for app, use `target='_blank'`. When building for the Web, don't use it. – Ricardo Panaggio Sep 30 '13 at 17:15
-
But I don't have a separate build, it's just a website which is also usable as a Firefox OS app :\ – Brendan Long Sep 30 '13 at 17:17
-
In that case, you'll have to rely on JavaScript. I'd say it's not the best approach, but it's doable. – Ricardo Panaggio Oct 11 '13 at 12:48
5
If you don't want to change all the links in the application, you can use WebActivities, e.g. like this:
/*
* Open all external links in the browser
*/
$('a[href^=http]').click(function(e){
e.preventDefault();
var activity = new MozActivity({
name: "view",
data: {
type: "url",
url: $(this).attr("href")
}
});
});

rge
- 106
- 6