I am trying to display a webpages using in-app-browser in android platform of phone gap.
window.open() opening a url webpage which can call another html pages on to the server. I am trying to close the in-app-browser on any page (i.e., on very first loaded page or on intermediate page loaded or on the last page) by clicking a close hyperlink which calls a javascript function iabClose(event)
but the in-app-browser is not closing.
Please help me if anybody knows the solution or any other better way of closing in-app-browser.
Thanks in advance
Code:
<html>
<head>
<script type="text/javascript" charset="utf-8">
var iabRef = null;
function inApp() {
iabRef = window.open('http://202.65.155.246/Real_Time_Data /SSEClient.aspx', '_blank', 'location=no');
iabRef.addEventListener('loadstop', iabLoadStop);
iabRef.addEventListener('exit', iabClose);
}
function iabLoadStop(event) {
if(event.url == "http://202.65.155.246/Real_Time_Data/CloseIAB.aspx"){
iabRef.close();
}
}
function iabClose(event) {
iabRef.removeEventListener('loadstop', iabLoadStop);
iabRef.removeEventListener('exit', iabClose);
}
</script>
<title>Hello World</title>
</head>
<body>
Click Here </br></br>
Exit
</body>
</html>
Related
Now I am developing a time reminder application where I need to display an alert message every hour. The alert must also be displayed when the application is running in background and in offline mode as well.
It should work for both Android and iOS platforms.
Please help me out this. Thanks in Advance.
Try using this Local Notification Plugin. Your code needs to look something like this:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
function onDeviceReady() {
// Now safe to use device Plugins
cordova.plugins.notification.local.schedule({
id: 1,
text: 'My first notification',
every: 'hour',
firstAt: next_monday,
data: { key:'value' }
});
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>
I have a html page, I want to launch my native app when loading this page. the following is my code:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://code.jquery.com/jquery-1.12.1.js"></script>
</head>
<body>
<br><br><br>
<a id="link1" style='display:none' href="baidufe://schemedemo/get/info?id=10000">test link</a>
<br>
<button onclick="launch()">Launch</button>
</body>
<script language="JavaScript">
function launch(){
console.log("test");
var clickTarget = document.getElementById("link1");
clickTarget.click();
};
window.onload=function(){
launch();
};
</script>
</html>
But when i open this page in android chrome(version is 49), my native app isn't launched. when i click the "Launch" button, my native app can be successfully launched.
what's root cause? but my requirement is native app will be launched when opening this page, how to fix it? Thank!
That seems like a rather indirect way to accomplish that you want...instead of simulating a click event, why not set the window location directly and skip a step?
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
<script>
setTimeout(function() {
window.location = 'baidufe://schemedemo/get/info?id=10000'
}, 250);
</script>
</html>
Keep in mind automatically redirecting users this way has a ton of edge cases, and may show a nasty 'Page could not be found' error if they don't have your app installed.
I'm new to Phonegap and having problems firing 'deviceready' event. Initially when run for the first time, the 'deviceready' event fired and worked. Later as I added more events ('backbutton', 'menubutton'...), I noticed 'deviceready' event and all other events stopped firing.
Here is the index.html code:
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function onBodyLoad() {
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
alert("Device Ready!!!");
}
</script>
</head>
<body onload="onBodyLoad()">
First PhoneGap App...
</body>
</html>
I have reviewed similare post in StackOverFlow and tried all options but still does not seem to work.
Please help me at the earliest as I need to quickly learn PhoneGap for further implementation. Hoping quick response.
Thanks,
RK
you can simply use following code for trigger various events like (backbutton,menubutton)
in script tag
$(document).ready(function()
{
document.addEventListener("deviceready", appReady, false);
function appReady()
{
document.addEventListener('backbutton', function(e){
var activePage = $.mobile.activePage.attr('id');
if(activePage == 'main')
{
if (confirm("Press a button!"))
{
alert("You pressed OK!");
navigator.app.exitApp();
}
else
{ alert("You pressed Cancel!");
}
}
}, false);
}
});
I'm developing an html5/JqueryMobile/Phonegap app. I have to detect the device language to redirect to a specific html. I'm trying to use Phonegap's navigator.globalization.getPreferredLanguage. On an iOS device it works fine.
The code below detects the language "onDeviceReady" and performs the redirect. This code should be universal for iOS and Android but when I try it on an Android device it doesn't work. The screen freezes. What might cause this?
<!DOCTYPE HTML>
<html>
<head>
<title>Language</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.globalization.getPreferredLanguage(
function (language)
{
if(language.value == "it")
{window.location.replace("index_it.html");}
else if (language.value == "ar")
{window.location.replace("index_ar.html");}
else
{window.location.replace("index_en.html");}},
function ()
{
alert('Error getting language\n');
}
);
}
</script>
</head>
<body>
</body>
</html>
Problem here, is that language received from Android will have different format, for example instead of Russian with code ru it will return русский
I am new to PhoneGap.
My application has to 2 pages. The first is loading fine. First page contains one buttons, which when clicked should move to the second page. How to load the second page? Should I prepare one more activity extending DriodGap?
I have one more problem: how to catch back button events?
Code to navigate to another html page.
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad()
{
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady()
{
// navigator.notification.alert("PhoneGap is working");
}
function callAnothePage()
{
window.location = "test.html";
}
</script>
</head>
<body onload="onLoad();">
<h1>Welcome to PhoneGap</h1>
<h2>Edit assets/www/index.html</h2>
<button name="buttonClick" onclick="callAnothePage()">Click Me!</button>
</body>
Code for back Event.
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady()
{
document.addEventListener("backbutton", BackKeyDown, true);
}
function BackKeyDown()
{
navigator.notification.alert();
//navigator.app.exitApp(); // For Exit Application
}
</script>
You need to redirect from Javascript like this:
HTML Code:
<a id="loginLnk" href="javascript:(void)">Login</a>
Javascript code:
document.getElementById("loginLnk").addEventListener("click", function(){window.location = "/test.html";});