How to open a web page from my application?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Opening a web page from an application usually means handing a URL to the system's default browser or presenting an in-app browser view. The right approach depends on the platform and on whether you want the user to leave your app or stay inside it.
The Two Main Choices
Most applications choose one of these:
- open the system browser
- show the page inside the app
The system browser is simpler and gives users all their normal browser features. An in-app browser gives a more controlled experience but may require extra UI work and security review.
Android: Open the System Browser
On Android, the standard pattern is an ACTION_VIEW intent with an HTTP or HTTPS URI:
If you are calling this from an Activity, that is usually enough. If you need safety checks, verify there is a matching activity before starting the intent.
iOS: Use UIApplication
In UIKit, opening a web page in the system browser is straightforward:
If you want the user to stay inside the app on iOS, SFSafariViewController is often the better choice than a raw web view for normal external pages.
Web Apps: Use window.open or Navigation
In a browser-based application, you can navigate the current tab or open a new one:
Use noopener and noreferrer when opening new tabs for security and isolation.
If you want to replace the current page instead, assign to window.location.href.
Desktop Python Example
For a desktop utility written in Python, the standard library already provides a browser launcher:
That opens the configured default browser without platform-specific code.
Choosing Between External and In-App Browsing
Use the external browser when:
- the page is a normal public website
- users may want saved passwords, bookmarks, or tabs
- you do not need tight in-app control
Use an in-app browser when:
- the page is a short supporting flow
- you want easy return to the app
- you need a more integrated user experience
On mobile, avoid embedding arbitrary websites in a plain web view unless you have a clear reason. System browser views are usually safer and easier.
Validate the URL First
Do not open arbitrary strings without validation. At minimum:
- ensure the URL is syntactically valid
- prefer
https - reject unsafe or unexpected schemes unless you explicitly support them
This matters especially when the URL comes from user input, remote configuration, or database content.
Common Pitfalls
The biggest mistake is assuming every string is a valid URL. Invalid URLs often fail silently or crash at the conversion layer.
Another mistake is using a raw embedded web view when a system browser or secure in-app browser controller would be simpler and safer.
People also forget platform lifecycle details. Opening an external browser may background your app, so any unsaved UI state should already be committed.
Finally, if you open new browser tabs from a web app, use noopener and noreferrer when appropriate to reduce security risk from the opened page.
Summary
- Opening a web page usually means either launching the system browser or using an in-app browser.
- Android uses an
ACTION_VIEWintent with a web URL. - iOS can open URLs with
UIApplication.shared.open. - Web apps use
window.openor normal navigation. - Validate URLs and choose the browsing model that fits the user experience and security requirements.

