Open Browser Fires Error

215 views
Skip to first unread message

Nii Darko Darkoh

unread,
Apr 26, 2021, 9:25:43 AM4/26/21
to DroidScript
Hello Droidscript,
I need help to solve the following issue:
whenever i use the ff JavaScript commands to open an url, I get the error "_Run is not defined" error.
The commands are as follows: 

1.
window.open("https://www.w3schools.com"); 
var params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no, width=0,height=0,left=-1000,top=-1000`;        
open('https://www.w3schools.com', 'test', params);
 
2.  
document.open("https://www.w3schools.com");
        
3. 
location.href = "https://www.w3schools.com";

How do I solve this please?

Alan Hendry

unread,
Apr 26, 2021, 10:32:24 AM4/26/21
to DroidScript
Hi,
Not sure if you mean in a native DS app, or an HTML app.
Could you post an SPK?
When you say " ff" do you mean FireFox?
I would normally assign the new window to a variable
   window1 = window.open("https://www.w3schools.com"); 
AFAIK negative left and top are not allowed, and minimum width and height are 100.
Not sure that open (sans window.) is valid
As far as I know document.open is to open a file to write to it (section 2)
There's also 
window.location.assign ("https://www.w3schools.com"); // replaces current page
location.replace("https://www.w3schools.com"); // replaces current page,can't go back
Regards, ah

Nii Darko Darkoh

unread,
Apr 26, 2021, 11:59:39 AM4/26/21
to DroidScript
Forgive me for not providing enough details.
1. I am developing an HTML app
2. The methods I posted open the pages alright..but when I close
The browser and return to my DS app, I get the script error.
3. I am using raw javascript codes not native DS code
I don't know if I can catch the error in onResume()
Thanks Alan.

Alan Hendry

unread,
Apr 28, 2021, 7:13:13 AM4/28/21
to DroidScript
Hi,
Sorry, still not understanding.
When I say "HTML app", I mean that when you first create your app, you choose HTML from the drop-down
   (code probably starts with <html>).
And I say "DS app", I mean that you choose Native
   (code will usually include function OnStart() ).
Can you post the significant steps in the code, and the actions the user performs?
Or it may be worth "stepping back" from the code and look at what you are trying to achieve (and figure out how to code it).
Regards, ah

Nii Darko Darkoh

unread,
Apr 28, 2021, 7:38:25 AM4/28/21
to DroidScript

Hi Alan, thank you for your patience.
Yes, I chose HTML when creating the project.
Please see my full code below:

<html>
<head>
    <meta name="viewport" content="width=device-width">
    <script src='file:///android_asset/app.js'></script>
</head>
<script>
    //Called after application is started.
    function OnStart(){
        app.ShowPopup( "HTML Rocks!" );
    }
    
    function openbrowser(){
       window.open("https://www.w3schools.com");
       //return;
    }
    
    
</script>

<style>
body { background-color: #ffffff; }
    .hello 
    { 
        font-size: 42; 
        width: 100%;
        margin-top: 2em;
        text-align: center;
        color: blue;
    }
</style>

<body onload="app.Start()">

<div class=hello> 
   <button onclick="return openbrowser(); "  ) > OPEN BROWSER </button>
</div> 
</body>
</html>

Nii Darko Darkoh

unread,
Apr 28, 2021, 7:40:59 AM4/28/21
to DroidScript
So to test, run the app and  hit the OPEN BROWSER button.
After the browser opens (chrome for me), tap the BACK key ..and the app crashes.
Thank you.

Alan Hendry

unread,
Apr 28, 2021, 9:32:59 AM4/28/21
to DroidScript
Hi,
I think the error occurs when you switch apps (close browser or switch back to DS).
AFAIK a button click doesn't need a value returned, but this doesn't fix it either
<button onclick="openbrowser()">
Removing    <script src='file:///android_asset/app.js'></script> and changing to <body>
seems to fix it, so I presume something in :///android_asset/app.js is responsible
Needs some-one technical to look at that (I'm not very au fait with html apps and app.js).
If you create a Native app, put your html in a file, then read it and open a webview with option IgnoreErrors
then when you click the button it goes to w3schools, and when you go back it goes back to your page.
Typing this in here, so there may be typos.
wv = app.AddWebView(lay,1,1,"IgnoreErrors") ;
html = app.ReadFile("html.html") ;
wv.LoadHtml(html) ;
Regards, ah

Nii Darko Darkoh

unread,
Apr 28, 2021, 12:43:10 PM4/28/21
to DroidScript
Hi Alan, you wrote as FF
"If you create a Native app, put your html in a file, then
 read it and open a webview with option IgnoreErrors
then when you click the button it goes to w3schools, and 
when you go back it goes back to your page."

Does it mean ...
1. if I create a native app I can add an HTML file?
2. I can use the webview to open a local/project file
to view it's content?
Droidscript team Kindly look into this for us.
Thank you Alan.

Alan Hendry

unread,
Apr 28, 2021, 4:16:02 PM4/28/21
to DroidScript
Hi,
I created a new Native app, added your html etc in a new file
See SPK
Regards, ah
wv.spk

Nii Darko Darkoh

unread,
Apr 28, 2021, 5:08:39 PM4/28/21
to DroidScript
Thanks Alan. I will try it out and revert.

Nii Darko Darkoh

unread,
Apr 28, 2021, 5:40:50 PM4/28/21
to DroidScript
Hi Alan, I tried the project. It's okk except for one problem.
When the browser opens and the back key is tapped, it closes the app all together.
This time no error shows though.
How do we return to the layout interface?
Thanks.

Alan Hendry

unread,
Apr 29, 2021, 5:40:13 AM4/29/21
to DroidScript
Hi,
Because you are opening a new window, it is opening the browser for w3schools.
Back exits the browser,  and returns to Android Home; you can go back to your app by choosing Recent Apps (bottom right icon).
Pretty sure we need to look at what you are trying to achieve.
You could have a native button "OpenBrowser", and a webview, when the button is clicked then wv.LoadUrl("https://w3schools.com")
If you want a whole bunch of buttons with a bunch of sites you may need to show the buttons only, 
and when clicked switch to a layout with a close button and a webview
the close button would show the original layout with the bunch of buttons.
You can switch layouts using Layout Hide/Gone/Show, or Drawers or Dialogs, Tabs, etc.
Regards, ah

Nii Darko Darkoh

unread,
Apr 29, 2021, 6:43:55 AM4/29/21
to DroidScript
Thank you Alan,

I am trying to create an html app that will use a webview to open a payment page.
the paymentt page(mastercard) disallows me because i am using iframe.
So i decoded to trick DS to enable me leverage the native js to use the webview to display the page.

Frankly I have finished creating it. VISA works with my iframe but mastercard disallows iframe, so I am exploring
options with the webview. To rewrite the pp in native will be difficult because its taken 6 montghs to do this in html.

But then a little expirement revealed that even webview display of a browser posses some complications with regard to returning to 
the app from the browser. It takes you to the android desktop.

How can I get a solution to this problem of mine??

Thank you Alan.

Alan Hendry

unread,
Apr 29, 2021, 9:21:59 AM4/29/21
to DroidScript
Hi,
Continuing with the Native app ...
You could make your function openbrowser run some DS app code
I tested a simple function openbrowser(){app.ShowPopup("hi")}
I don't know if you need the HTML to construct the MasterCard URL and pass it from the onclick in the HTML to openbrowser,
then openbrowser would receive the URL, switch to a 2nd layout with another webview with LoadUrl for the MasterCard URL
Probably simplest would be a close button in the 2nd layout and ontouch to switch back to the 1st layout.
(or use SetOnUrl to detect that the user has got to a "payment completed" screen - see other posts about SetOnUrl).
Regards, ah


Nii Darko Darkoh

unread,
Apr 30, 2021, 5:56:01 PM4/30/21
to DroidScript
Alan, I think I finally got the solution I was looking for..
It's app.OpenURL. I found it in one of my old apps..as follows

<a onclick=app.OpenUrl("https://chat.whatsapp.com/Hf91MwUOyBkKFI51KlDhc") style="text-align: left;font-size:13px;color:blue;">Join our WhatsApp Family</a>

   Thank you for all your time and effort.

Reply all
Reply to author
Forward
0 new messages