Open a web link with in the app itself in jquery mobile - android

I want to open a url(ex. www.google.com) in jquery mobile android app.
I want to open it with in the context of the app itself. i dont want to open a diffrent browser to launch it on the click of the link or button. i want to open it with in the app.
is it possible.
Thanks.

Found the solution here:
function openInWebView(url)
{
var anchor = document.createElement('a');
anchor.setAttribute('href', url);
var dispatch = document.createEvent('HTMLEvents')
dispatch.initEvent('click', true, true);
anchor.dispatchEvent(dispatch);
}
Then call the function like this in your app:
openInWebView('http://google.com')

Related

Android and custom URL scheme

I'm working on an app with a custom url scheme.
It is opening some webpage for authentication in a chrome tab. This is done in xamarin forms like this:
Browser.OpenAsync(apiUrl + "mobile", new BrowserLaunchOptions
{
LaunchMode = BrowserLaunchMode.SystemPreferred,
TitleMode = BrowserTitleMode.Hide,
});
everything work as expected if I return a webpage with a link and click the the link manually:
Click here to go the app
But if i return a 302 redirect to the same url it will not close the chrome tab and dont focus the app again.
If i add a javascript in the response, it will not automatically open the url (close the chrome tab and focus the app)
I've tried things like this:
window.location = url;
window.open(url,'_self');
setTimeout(()=>window.open(url,'_self'),10);
(url is a valid variable, even tried alert(url) after changing the location and it show the correct url.
Why does it only work when I click the link manually?
In order to maintain the user's security and experience, the browser prohibits the direct use of window.open(URL) in JS to open new links.
Try to change like below:
setTimeout(()=>window.open(url,'_self'),500); //The delay time must not be too short or you will be intercepted

WebView open apps/default browser

I am quite new to React-native. The href tag in HTML opens the website within the app. I wish to have it open the link in the default browser of the mobile phone/device. Oh and I use snack.expo.
In APP a website is being loaded. Within my website I use <a href> 'http://maps.google.com/?q=...' I wish to have the default browser of a mobile phone to open this link in its default browser, same goes for other href links.
Of course only links with target="_blank" should be opened in the default browser.
It would be even more awesome if app's can be opened.
I have searched google a lot, but without success.
Anyone who knows how to do this? Or is it simply not available, yet?
Within my HTML code I've tried this:
{address}
Part of react native code:
return (
<WebView
source={{ uri: '{website}' }}
/>
);
Best regards
It is definitely possible in react native. You can do it as follows:
import {Linking} from "react-native"
<WebView
source={{uri:"https://mashupguide.net/1.0/html/ch02s05.xhtml"}}
onShouldStartLoadWithRequest={request => {
let url = request.url;
if (url.includes("http://maps.google.com/")) {
Linking.openURL(url);
return false
} else {
return true
}
}}
/>
This will prevent the WebView from browsing to the next page and instead open the phone's default browser.
reference: https://github.com/react-native-community/react-native-webview/blob/master/docs/Reference.md#onshouldstartloadwithrequest
working example: https://snack.expo.io/#ammarahmed/sadistic-almond

How can I automatically close the InAppBrowser after post has been shared?

I am fairly new to Ionic and Cordova and I am using Cordova to create an application.
I've written code to open an InAppBrowser window in order to share a link via Google+.
My code works fine however, once the user has shared the link they are redirected in the InAppBrowser to their Google+ page. How would I go about closing the InAppBrowser window after the user has successfully shared their post?
$scope.googleShare = function(url){
var siteToShare = "https://plusone.google.com/_/+1/confirm?hl=en&url=<?php echo rawurlencode("+url+")";
var options = "location=no,toolbar=yes,toolbarposition=top"
var ref = window.open(siteToShare, '_blank', options);
ref.addEventListener('loadstop', function(event){
if(event.url.match("mobile/close")){
ref.close();
}
})
console.log(siteToShare);
}
You can automatically close the InAppBrowser by listening for the loadstart event, which is fired whenever the browser starts loading a new page. If you use loadstop, the user will see that the browser goes to a different page.
The following code is an example as to how you can close the browser using the loadstart event. All you have to do is replace "part of URL here" with whatever works for you.
ref.addEventListener('loadstart', function(event) {
if(event.url.indexOf("part of URL here") > -1) {
ref.close();
}
});

Xamarin Forms - iOS Use webView in app, and not in default browser

I'm been using the WebView in my project to show a couple of webpages in app.
On Android this works fine. but on iOS it's open the default browser insted of showing it in app, like when you use
Device.OpenUri(new Uri(e.Url))
My code look like this
webView = new WebView
{
Source = new UrlWebViewSource
{
Url = "http://www.google.com",
},
VerticalOptions = LayoutOptions.FillAndExpand
};
this.Content = webView ;
Any one here who know how to make the iOS open the page in-app ?
Using Device.OpenUri will often even according to the Xamarin documentation here, navigate outside the application.
If you want to host the content within your application, the best approach would be to embed the Webview, that it looks like your doing, and set the .Source to a url.
I don't understand why your using Device.OpenUri if you have a WebView instance already on your page.
Just set the .Source property of the WebView to point at some url.
For example:-
WebView objMyWebView = new WebView();
objMyWebView.Source = "http://www.google.com";

Phonegap android: how to open external url from local html pages?

I am trying to open en external url from a local html file. For example, i am using super.loadUrl("file:///android_asset/www/index.html"); to call local file and the application opens it in the browser provided by DroidGap. However, there is a problem with the external url. In index.html, i am trying to reach http://www.google.com via an image button and the device opens another browser to show www.google.com (in my device, chrome is opening to show the page www.google.com). I want to let DroidGap browser to open both external and local urls in DroidGap browser.
I have achieved this because I needed the same solution. I assume you already know how to load the local file but just in case ...
//By "SomeLocalFile.html" I mean an html file in the /www/ folder of the actual app installation **not** on the server
var ref = window.open('somelocalfile.html', '_blank', 'location=no');
First Add and event listener like this to the main js of your app from which you are calling var ref = window.open().
ref.addEventListener('loadstart', LoadStart); // in YourMainJs.js
Then create a local file called closeInAppBrowser.html some where in your /www/ folder it just so happens that mines is in /www/pages/
Now define the LoadStart function so that when the page starts to load LoadStart() will fire
//I use match(/[^/]+$/g) because I find that matching the file name is just easier than the path.
// This code is place in in YourMainJs.js
fileName = event.url.match(/[^/]+$/g);
if(fileName[0] == "closeInAppBrowser.html"){
// alert("fun load stop runs");
ref.close();
}
Now in the SomeLocalFile.html that you are going to use window.open() with, place a link and js like this.
// in SomeLocalFile.html that was called via the window.open()
<a class="close">Close This Window Like A BOSS!</a>
$('.close').click(function(){
//We use window location cause you can't navigate to any other local file just by using an href in an <a> tag
//We aslo use ../../ because that is the correct path usage from within InAppBrowser to another local file
window.location = '../../pages/closeInAppBrowser.html';
});
Now when you click the link it will attempt to navigate to closeInAppBrowser.html this will trigger LoadStart() and it will check if the event.url file name matches "closeInAppBrowser.html" and if so it will close the window.
I have tested this and it works 100%. Let me know if you have any other questions
Actually there is no need to use child browser plugin, if you upgrade phonegap to 2.3.0 or above, so that you can use InAppBrowser
sample
var ref = window.open(authorize_url, '_blank', 'location=no');
ref.addEventListener('loadstart', function() { me.locChanged(event.url,ref); });

Categories

Resources