location.href Help!

My application is compiled on the PhoneGap installed on my machine:
I use location.href = “https://www.papelaria.net” to go to my website! How do I return to the app to execute a function of my application like cordova.plugins.barcodeScanner.scan (codcerto, coderro)
How do I make my page call any of the functions below?

Example my code:

Sub Main

If location.search="" Then
location="https://www.papelaria.net"
Exit Sub
Else
  buscar=Mid(location.search,2,Len(location.search))
  comando=Split(buscar,"&")
  If comando(0)="barra" Then
         cordova.plugins.barcodeScanner.scan(codcerto, coderro)
   End If 
End If


End Sub
Function codcerto(result)
 MsgBox result.text
End Function
Function coderro(result)
 MsgBox result.text
End Function
Function busca()
  MsgBox "Veio aqui"
End Function

Let’s unpack this:

Compiled on Phonegap? Meaning Phonegap Build?

Installed in my machine? (Phone?)

Location.href should open an external window, you can’t really get back from that. Instead use the inappbrowser plugin and open a faux browser window (it doesn’t have nav bars etc)

I will try this inappbrowser thanks a lot! If it works it came back here to say it worked!
My language is portuguese use google translator

My code is returning this error below:

Unable to get property 'open' of undefined or null reference. 
line 8 column 5

I’ve done the installation on my phone gap
cordova plugin add cordova-plugin-inappbrowser
I don’t know what it can be anymore, can you help me?

Follow the code below:

Dim ref
Dim target
Dim options
Sub Main
target = "_blank"
options = "location=yes,hidden=yes,beforeload=yes"
ref = cordova.InAppBrowser.open("https://www.papelaria.net", target, options)
ref.addEventListener("callback",start(event)) 
' SetTimeout(fechar(),15000)
End Sub

Function start(event)
console.log("Passou aqui st " & event)

End Function

Are you running this in the PhoneGap app on your device?

Share your story with the AppStudio Community! Quarantine Stories

It’s a simple plugin add:

  <plugin name="cordova-plugin-inappbrowser" source="npm" spec="3.1.0" />

Call it like this:

window.open = cordova.InAppBrowser.open; // replace the default window.open
<a href="#" onclick="window.open('https://www.mydomain.com/privacy-policy','_system', 'location=yes');">Read Our Full Privacy Policy Here</a>

I finally managed to make it work perfectly!
Follow the code that works on mobile! Note: Does not work in the browser works only through the apk file!
Follow functional code! Thank you all!


Dim url
Dim siteretorno
Dim iabRef 

Sub Main
    url="https://www.papelaria.net/index.php"
    document.addEventListener("deviceready", onDeviceReady, False)
End Sub



Function onDeviceReady() 
         iabRef = window.open(url, "_blank", "location=no,fullscreen=yes,zoom=no")
         iabRef.addEventListener("loadstart", iabLoadStart)
         iabRef.addEventListener("loadstop", iabLoadStop)
         iabRef.addEventListener("loaderror", iabLoaderro)
         iabRef.addEventListener("beforeload", beforeloadCallBack)
       End Function
     
       Function iabLoaderro(params) 
        If params.message="ERR_NAME_NOT_RESOLVED" Then
        Alert1.value="Sem sinal de Internet:Endereço Não Resolvido:"
        iabRef.close
        ChangeForm(Form2)
        End If
        If params.message="ERR_ADDRESS_UNREACHABLE" Then
        Alert1.value="Sem sinal de Internet: Endereço Inacessível!"
        iabRef.close
        ChangeForm(Form2)
        End If
      
        If params.message="ERR_CACHE_MISS" Then
        Alert1.value="Perca de Cache!"
        iabRef.close
        ChangeForm(Form2)
      Else
        Alert1.value="Erro desconhecido!"
        iabRef.close
        ChangeForm(Form2)
        End If
        
       End Function
     
 Function iabLoadStart(event) 
        Textarea1.text=Textarea1.text & vbCRLF & event.url;
        console.log(event.type & "-" & event.url)
        campo=Split(event.url,"?")
        If campo(0)="https://www.papelaria.net/codigodebarra.php" Or campo(0)="https://www.papelaria.net/codigodebarra.php/" Then
        comando=Split(campo(1),"&")
        Textarea1.text=Textarea1.text & vbCRLF & "comando:" & comando(0)  
        If comando(0)="cmd=codigodebarra" Then
        Textarea1.text=Textarea1.text & vbCRLF & "Entrou para executar"
        retorno=Split(comando(1),"=") 
        siteretorno=retorno(1)
        iabRef.close
        cordova.plugins.barcodeScanner.scan(codcerto, coderro)
        End If
        End If
      End Function
      
      
     

    Function iabLoadStop(event) 
        Textarea1.text=Textarea1.text & vbCRLF & event.url
        console.log(event.type & "-" & event.url)
        campo=Split(event.url,"?")
        If campo(0)="https://www.papelaria.net/codigodebarra.php" Or campo(0)="https://www.papelaria.net/codigodebarra.php/" Then
        comando=Split(campo(1),"&")
        If comando(0)="cmd=codigodebarra" Then
          retorno=Split(comando(1),"=") 
          urlretorno=retorno(1)
          
        iabRef.close
        cordova.plugins.barcodeScanner.scan(codcerto, coderro)
        End If
        End If
    End Function

    Function codcerto(result)
      url="https://www.papelaria.net/" & siteretorno & "?codigobarra=" result.text
            document.addEventListener("deviceready", onDeviceReady, False)  
    End Function
        Function coderro(result)
        console.log(result.text)
        End Function

Awesome! Good for you!

Great!

A tip: if you right click in the Code Window, you can reformat your code. It will clean up the indentation.

Share your story with the AppStudio Community! Quarantine Stories

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.