launch a default/native browser with javascript blackberry app - javascript

<?xml version="1.0" encoding="utf-8"?><widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0" rim:header="ipaidabribenaija.com Breaking News and News Updates">
<name>ipaidabribenaija.com</name>
<description>First for Breaking News and News Updates</description>
<content src="index.html" rim:allowInvokeParams="true"/>
<author href="http://www.centurymegasystem.com" rim:copyright="Copyright 2012 wwww.ipaidabribenaija.com" email="josiahaccounts#gmail.com" xml:lang="en" its:dir="rtl" >Josiah Gerald</author>
<feature id="blackberry.invoke.BrowserArguments" />
<rim:connection timeout="25000">
<id>TCP_WIFI</id>
<id>MDS</id>
<id>BIS-B</id>
<id>TCP_CELLULAR</id>
<id>WAP2</id>
<id>WAP</id>
</rim:connection>
<license>Copyright (c) 2012 ipaidabribenaija.com.</license>
<icon src="images/icon.png" /></widget>
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Breaking News and News Updates</title>
<script type="text/javascript">
var args = new blackberry.invoke.BrowserArguments('http://www.ipaidabribenaija.com');
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
/*function openWebLinkInBrowser() {
// open web link in browser
blackberry.invoke.invoke({target: "sys.browser",uri: "http://www.ipaidabribenaija.com"});
}
openWebLinkInBrowser();*/
</script>
I am a newbie in this programming. I am given a task to develop an app for BlackBerry.
Once the app is launched, the browser will open to a specific URL.
I got a java code that does this. How can I achieve the same with BlackBerry Webwork API.
The code above is what I have achieve so far. However, the app is not launching the browser on load.
Thanks for your time and idea in advance.
<?xml version="1.0" encoding="utf-8"?><widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0" rim:header="ipaidabribenaija.com Breaking News and News Updates">
<name>ipaidabribenaija.com</name>
<description>First for Breaking News and News Updates</description>
<content src="index.html" rim:allowInvokeParams="true"/>
<author href="http://www.centurymegasystem.com" rim:copyright="Copyright 2012 wwww.ipaidabribenaija.com" email="josiahaccounts#gmail.com" xml:lang="en" its:dir="rtl" >Josiah Gerald</author>
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
<feature id="blackberry.invoke" />
<rim:connection timeout="25000">
<id>TCP_WIFI</id>
<id>MDS</id>
<id>BIS-B</id>
<id>TCP_CELLULAR</id>
<id>WAP2</id>
<id>WAP</id>
</rim:connection>
<license>(c) 2012 ipaidabribenaija.com.</license>
<icon src="images/icon.png" /></widget>
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Breaking News and News Updates</title>
<script type="text/javascript">
var args = new blackberry.invoke.BrowserArguments('http://www.ipaidabribenaija.com');
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
blackberry.app.exit();
</script>
The above code works fine, i tested it on BB simulator 9930.
Thanks for the help #HelpMeToHelpYou.

<script type="text/javascript">
var args = new blackberry.invoke.BrowserArguments('http://www.blackberry.com');
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
</script>
You must declare the feature element(s) below in your configuration document:according to following image
More information please visit
https://developer.blackberry.com/html5/apis/blackberry.invoke.browserarguments.html
Sample Code:
Please make sure that config files as following
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:rim="http://www.blackberry.com/ns/widgets"
version="1.0" rim:header="WebWorks Sample">
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.BrowserArguments" />
<feature id="blackberry.identity" />
<name>Hello World</name>
<description>This is HelloWorld.</description>
<content src="index.html"/>
</widget>
And index.html as
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,
user-scalable=no">
<title>Hello World</title>
<script type="text/javascript">
function myFunction()
{
var args = new blackberry.invoke.BrowserArguments('http://www.blackberry.com');
blackberry.invoke.invoke(blackberry.invoke.APP_BROWSER, args);
}
</script>
</head>
<body onload="myFunction()">
<p>Hello World!</p>
</body>
</html>
try this

Related

Can't get Admob example ads to show in Cordova app

I have a simple app I made in vanilla JS that I want to convert to a mobile app. I can do it easily with Cordova, but I can't seem to get Admob ads to show up with any of the plugins I tried.
On this one I am using "admob-plus-cordova". I created it with the example app ID, and followed the instructions in the documentation. I just can't figure out why it doesn't work.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta
name="viewport"
content="initial-scale=1, width=device-width, viewport-fit=cover"
/>
<meta name="color-scheme" content="light dark" />
<link rel="stylesheet" href="css/index.css" />
<title>Admob</title>
</head>
<body>
<div></div>
<script src="cordova.js"></script>
<script type="text/javascript">
let banner
document.addEventListener(
"deviceready",
async () => {
await admob.start()
banner = new admob.BannerAd({
adUnitId: " ca-app-pub-3940256099942544/6300978111",
})
banner.on("impression", async (evt) => {
await banner.hide()
})
await banner.show()
},
false
)
</script>
</body>
</html>

Script doesn't work in WebView for react-native

I trying to add helpcrunch chat in my mobile app via WebView. For it I need to add a few scripts in HTML:
<script type="text/javascript">
(function(w,d){
w.HelpCrunch=function(){w.HelpCrunch.q.push(arguments)};w.HelpCrunch.q=[];
function r(){var s=document.createElement('script');s.async=1;s.type='text/javascript';s.src='https://widget.helpcrunch.com/';(d.body||d.head).appendChild(s);}
if(w.attachEvent){w.attachEvent('onload',r)}else{w.addEventListener('load',r,false)}
})(window, document)
</script>
<script type="text/javascript">
HelpCrunch('init', 'app', {
applicationId: 2,
applicationSecret: 'appKEY'
})
HelpCrunch('showChatWidget');
</script>
In IOS all work well. But on android, this script doesn't work.
Code with my WebView:
<WebView
injectedJavaScript={INJECTED_SCRIPTS}
onMessage={this.onMessage}
javaScriptEnabled={true}
automaticallyAdjustContentInsets={false}
source={{ html: `<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1 id="about">regnergioi</h1>
</body>
</html>` }}
style={{ marginTop: 30, marginBottom: 10, height: 400 }}
renderError={(a) => this.handleError(a)}
onError={(a) => this.handleError(a)}
/>
I can't really help with the WebView problem but I can suggest a unofficial HelpCrunch library for React Native.
It's a bit old but I think it will work fine after updating the SDK versions to latest for both platforms
https://www.npmjs.com/package/react-native-helpcrunch
Latest versions:
Android: 3.1.4 update here
iOS: 3.3.6 update here

Dark & Light Mode: How to switch manifest and favicon?

The manifest and the favicon are dependent on the light/darkmode is there any way of changing them as the user changes the mode in the operating system?
Ive got the event listener firing
window.matchMedia('(prefers-color-scheme: dark)').addEventListener( "change", (e) => {
if (e.matches) console.log('your in dark mode);
});
but the manifest is loaded from the react public folder..
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>My Site</title>
</head>
<body>
<noscript>Please enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
Not sure how to handle the favicon that is also in the root of the public folder. Also the meta tag for theme-color would need to change.
Using the suggestion from #kishore I've managed to get the favicon working, I'm sure someone better can tighten up my code but it works, in the html I added an id...
<link rel="shortcut icon" id='favicon' href="%PUBLIC_URL%/favicon.ico" />
<link rel="manifest" id='manifest' href="%PUBLIC_URL%/manifest.json" />
then in the head section I added...
<script>
const usesDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches || false;
const favicon = document.getElementById('favicon');
const manifest = document.getElementById('manifest');
function switchIcon(usesDarkMode) {
if (usesDarkMode) {
favicon.href = '%PUBLIC_URL%/favicon-dark.ico';
manifest.href='%PUBLIC_URL%/manifest-dark.json'
} else {
favicon.href = '%PUBLIC_URL%/favicon-light.ico';
manifest.href='%PUBLIC_URL%/manifest-light.json'
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener( "change", (e) => switchIcon(e.matches));
switchIcon(usesDarkMode);
</script>
you can change dynamically using js
document.getElementById('favicon_id').href = 'required_link'
do this inside onchange function

How to get content of html page which is modified by javascript

I have the html page which is loaded by cef chronium (for wpf) browser. And its content is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv = "cache-control" content = "max-age=0">
<meta http-equiv = "cache-control" content = "no-cache, must-revalidate">
<meta http-equiv = "expires" content = "0">
<meta http-equiv = "expires" content = "Tue, 01 Jan 1970 1:00:00 GMT">
<meta http-equiv = "pragma" content = "no-cache">
<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="styles/p2uweb.css" />
<title></title>
<script src="working/analitics.js"></script>
<script src="scripts/jq.min.js"></script>
<script src="scripts/jq.json.js"></script>
<script src="scripts/jq.webforms.js"></script>
<script src="scripts/jq.ismbrows.js"></script>
<script src="scripts/jq.popups.js"></script>
<script src="scripts/jq.cvv.js"></script>
<script src="scripts/jq.sbinder1.js"></script>
<script src="scripts/jq.hashstring.js"></script>
<script src="scripts/common.js"></script>
<script src="working/p2uweb.js"></script>
</head>
<body>
<div id="switcher"></div>
<div id="forms"></div>
</body>
</html>
I want to parse this page using HtmlAgility.HtmlDocument but I cannot see any controls (except divisions) in body. They all are loaded by some javascript files declared in header. How can I receive full page contents?
When I open Google Chrome I can press F12 and see all loaded contents. How can I make such things myself?

ReferenceError: Parse is not defined

I get this error with a Parse.com JS App:
ReferenceError: Parse is not defined.
I really don't know why. Everything looks good to me. The files are linked correctly; I've checked this a few times. Is it not true, that I have to put my own JS right below Parse and it should work? This is what I've read here: Github Project
I use Chrome with the ripple extension. I serve the app via cordova serve
Any help much appreciated!
Here is index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="../css/index.css" />
<link rel="stylesheet" type="text/css" href="../css/font-awesome.min.css" />
<title>Zone</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-latest.js"></script>
<script type="text/javascript" src="../js/main.js"></script>
</head>
<body>
<img src="../img/site-logo.png" rel="external" class="logo">
<!-- <div class="site-menu">
<i class="fa fa-angle-double-left"></i><p class="title"></p><i></i>
</div> -->
<img src="img/suche.jpg" class="icon">
<img src="img/essentrinken.jpg" class="icon">
<img src="img/einkaufen.jpg" class="icon">
<img src="img/kultur.jpg" class="icon">
<img src="img/dienstleistungen.jpg" class="icon">
<img src="img/nuetzlich.jpg" class="icon">
<img src="img/nummern.jpg" class="icon">
<img src="img/sport.jpg" class="icon">
<img src="img/verwaltung.jpg" class="icon">
<img src="img/hotel.jpg" class="icon">
<img src="img/neuzuzuger.jpg" class="icon">
<div class="adad"></div>
<script type="text/javascript" src="../cordova.js"></script>
<script type="text/javascript" src="../js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
And here the JS file.
$(document).ready(function () {
Parse.initialize("", "");
var Ad = Parse.Object.extend("Ads");
function getPosts() {
var query = new Parse.Query(Ad);
query.find({
success: function (results) {
console.log("hello");
var output = "";
for (var i in results) {
var name = results[i].get("location");
if (name == 10) {
output += "<img src = '" + imageurl + "' class='media-object' height='60' width='100'>"
}
}
$("#adad").html(output);
console.log(output);
},
error: function (error) {
console.log("Query error:" + error.message);
}
});
}
getPosts();
});
I'm sorry, I have no experience with Cordova, but in general I've seen problems like these being caused by live reloading of files or by asynchronous loading, which could be caused by cordova/gulp/nodejs.
Maybe you should use a require statement as shown on the Parse quick start guide: var Parse = require('parse');
When I try your html and javascript in jsfiddle it just works, so it should have something to do with the order of loading js files in your local "webserver".
The problem could be that the parse CDN was not found i.e . download the SDK and host it yourself instead
Just run into the same issue. You are most likely missing the reference to parse.min.js.
The reference is typically in your index.html file, inside the header:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<meta http-equiv="Content-Security-Policy"/>
<script type="text/javascript" src="cordova.js"></script>
<! ---- LOOK HERE --------->
<script src="js/parse.min.js"></script>
<! ---- LOOK HERE --------->
<link rel="stylesheet" type="text/css" href="css/one.css" />
<title>Title</title>
</head>
<body>
<div id="app"></div>
</body>
</html>

Categories

Resources