-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenAppDeepLinkv2.html
73 lines (63 loc) · 2.87 KB
/
OpenAppDeepLinkv2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Deep Link Test</title>
<script>
// Function to get a specific query parameter from the current page's URL
function getQueryParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
window.onload = function() {
// Get the appUrl and fallbackUrl from the query parameters
let appUrl = getQueryParam("appUrl");
const fallbackUrl = getQueryParam("fallbackUrl") || "https://www.kvb.co.in/personal/digital-products/kvb-dlite-mobile-banking/";
// If appUrl is missing, show an error message and exit
if (!appUrl) {
alert("Error: appUrl parameter is missing!");
return;
}
// Get additional parameters dynamically from the query string
const redirectTo = getQueryParam("RedirectTo");
const isPostLogin = getQueryParam("isPostLogin");
// Construct extra query parameters string if they exist
let extraQueryString = "";
if (redirectTo) extraQueryString += `RedirectTo=${encodeURIComponent(redirectTo)}`;
if (isPostLogin) {
extraQueryString += (extraQueryString ? "&" : "") + `isPostLogin=${encodeURIComponent(isPostLogin)}`;
}
// Append extra parameters to the appUrl if they exist
if (extraQueryString) {
if (appUrl.includes("?")) {
appUrl += "&" + extraQueryString;
} else {
appUrl += "?" + extraQueryString;
}
}
console.log("Final appUrl:", appUrl); // For debugging
// Start time to measure if the app opens
const startTime = Date.now();
// Attempt to open the app using window.location
window.location = appUrl;
// Set a timeout to check if the app opened or not
setTimeout(function() {
const endTime = Date.now();
// If the time difference is less than 1500ms, assume the app did not open
if (endTime - startTime < 1500) {
// Redirect to the fallback URL if the app did not open
window.location.href = fallbackUrl;
} else {
// Close the tab if the app opened successfully
window.close();
}
}, 1000);
};
</script>
</head>
<body>
<h2>Attempting to open the app...</h2>
<p>If the app is installed, it will open automatically. Otherwise, you'll be redirected shortly.</p>
</body>
</html>