0

I have a cordova app and I want to do the following:

  1. There is a link in an app like whatsapp or any other messenger, or in a mobile browser like chrome: www.example.com/site?p=xyz
  2. I click on that link and it should open my app "com.cordova.app" on the page "page.html?p=xyz", passing the parameter "p"

How can I do it? I found how to open a site in the inapp-Browser, but it does not what I am looking for.

Thank you for your answers, great community:)

Greetings, Phil

Philipp K
  • 1
  • 2
  • 1
    Does this answer your question? [how can cordova open app from http or https url?](https://stackoverflow.com/questions/28041677/how-can-cordova-open-app-from-http-or-https-url) – Eric Jan 20 '22 at 11:55

2 Answers2

0

To open your app using hyperlinks install 'cordova-plugin-customurlscheme'

cordova plugin add  cordova-plugin-customurlscheme --variable URL_SCHEME=fooapp

Initialize after onDeviceReady and add the function

window.handleOpenUrl = function(url) {
    //url contains the parameters you set in the hyperlink e.g. fooapp://dobar
}

External link will look like this:

<a href="fooapp://dobar">Open fooapp</a>
DGK
  • 2,947
  • 5
  • 32
  • 47
-1

If you want send the parameters for the URL , you are doing a http request, so, you should use ajax, with the method GET and you can send the parameters. Also, you need change the element , you can use <span id="url">www.example.com/site?p=xyz</span>

//CSS 
#url{
color:blue,
text-decoration:underline;
}

after in javascript code:

document.querySelector("#url).addEventListener("click", function(){
   let url = (this.text).split("?"); // you can use the object, navigator, too
   let parameters = url[0];
   
   // invoke the ajax function here sending the parameters, you can use filter, map or split, etc, for separte the vars and value vars. If the response is successfully, you can save the values or/and redirect another URL
})

for persistence with this values I recommend use sessionStorage or localStorage

David Tapias
  • 107
  • 2
  • 1
    Thank you for your answer. I should update my question to give more details, because it is not what I am looking for, I think. I forgot to mention, the link is in another app like whatsapp or any other messenger; big sorry – Philipp K Jan 20 '22 at 05:05