我有一個科爾多瓦應用程式,我想做以下事情:
- 在 whatsapp 或任何其他 Messenger 等應用程式或 chrome 等移動瀏覽器中有一個鏈接:www.example.com/site ?p=xyz
- 我單擊該鏈接,它應該在頁面“page.html?p=xyz”上打開我的應用程式“com.cordova.app”,并傳遞引數“p”
我該怎么做?我找到了如何在 inapp-Browser 中打開一個站點,但它不是我想要的。
謝謝你的回答,偉大的社區:)
問候,菲爾
uj5u.com熱心網友回復:
要使用超鏈接打開您的應用程式,請安裝“cordova-plugin-customurlscheme”
cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=fooapp
在 onDeviceReady 之后初始化并添加函式
window.handleOpenUrl = function(url) {
//url contains the parameters you set in the hyperlink e.g. fooapp://dobar
}
外部鏈接將如下所示:
<a href="fooapp://dobar">Open fooapp</a>
uj5u.com熱心網友回復:
如果你想發送 URL 的引數,你正在做一個 http 請求,所以,你應該使用 ajax,方法 GET 并且你可以發送引數。另外,您需要更改元素,您可以使用
<span id="url">www.example.com/site?p=xyz</span>
//CSS
#url{
color:blue,
text-decoration:underline;
}
在javascript代碼之后:
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
})
對于這個值的持久性,我建議使用 sessionStorage 或 localStorage
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/417754.html
標籤:
