I have a cordova app and I want to do the following:
- 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
- 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
CodePudding user response:
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>
CodePudding user response:
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
