share
Navigation & Sharing
Open URLs, share content, and navigate
Opening URLs
Open links in browser or other apps
shift2appjs.openUrl(url)
Opens a URL in the default browser or appropriate app.
Parameters
url
String - URL to open
Returns
void
// Open in browser
shift2appjs.openUrl("https://example.com");
// Open email
shift2appjs.openUrl("mailto:support@example.com");
// Open phone dialer
shift2appjs.openUrl("tel:+1234567890");
// Open maps
shift2appjs.openUrl("https://maps.google.com/?q=New+York");
// Open app store
shift2appjs.openUrl("https://play.google.com/store/apps/details?id=com.example.app");
shift2appjs.openUrlInApp(url)
Opens a URL inside the app WebView instead of external browser.
Parameters
url
String - URL to open
Returns
void
// Navigate to URL in app
shift2appjs.openUrlInApp("https://mysite.com/new-page");
shift2appjs.shareContent(title, text, url)
Opens the native Android share dialog.
Parameters
title
String - Share dialog title
text
String - Text content to share
url
String - URL to share (optional)
Returns
void
// Share a page
function sharePage() {
shift2appjs.shareContent(
"Check this out!",
"I found this amazing article",
window.location.href
);
}
// Share a product
function shareProduct(product) {
shift2appjs.shareContent(
product.name,
product.description + " - Only $" + product.price,
"https://mystore.com/product/" + product.id
);
}
shift2appjs.shareImage(imageUrl, text)
Shares an image with text via the native share dialog.
Parameters
imageUrl
String - URL of the image to share
text
String - Caption or text to share with image
Returns
void
// Share product image
shift2appjs.shareImage(
"https://mysite.com/images/product.jpg",
"Check out this amazing product!"
);
shift2appjs.goBack()
Navigates back in the WebView history.
Returns
void
// Custom back button
document.getElementById("backBtn").onclick = () => {
shift2appjs.goBack();
};
shift2appjs.canGoBack()
Checks if there is history to go back to.
Returns
Boolean - true if can go back
// Show/hide back button
if (shift2appjs.canGoBack()) {
document.getElementById("backBtn").style.display = "block";
} else {
document.getElementById("backBtn").style.display = "none";
}
shift2appjs.reload()
Reloads the current page.
Returns
void
// Reload button
document.getElementById("reloadBtn").onclick = () => {
shift2appjs.reload();
};
shift2appjs.exitApp()
Closes the app.
Returns
void
// Exit confirmation
function exitApp() {
if (confirm("Are you sure you want to exit?")) {
shift2appjs.exitApp();
}
}