window.location.replace("https://target_url/"+profile.userId); 改成 location.href = profile.userId; 這樣呢?
- 0
大家好,想請問是否有人跟我遇到一樣的問題
我在使用LIFF v1或v2的時候,都會遇到iOS系統的手機無法像android手機那樣開啟一個視窗進行跳轉的動作
以下是我跳轉的LIFF網頁所使用的code:
LIFF v1版本
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8" />
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<title>網頁跳轉中...</title>
<script charset="utf-8" src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script>
window.onload = function (e) {
liff.init(function (data) {
initializeApp(data);
});
};
function initializeApp(data) {
// openWindow call
//document.getElementById('openwindowbutton').addEventListener('click', function () {
liff.openWindow({
url: 'https://target_url'+data.context.userId,
external:false,
});
liff.closeWindow();
}
</script>
</head>
<body>
<script src="https://d.line-scdn.net/liff/1.0/sdk.js"></script>
</body>
</html>
LIFF v2版本
<!DOCTYPE html>
<html>
<head>
<META HTTP-EQUIV="EXPIRES" CONTENT="0">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8" />
<title>‎</title>
<script src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script>
$(document).ready(function () {
// Using a Promise object
liff.init({
liffId: '1655910264-WMJaqd2n' // Use own liffId
})
.then(() => {
// Start to use liff's api
liff.getProfile()
.then(profile => {
if (liff.getOS() == "ios") {
console.log('ios系統');
window.location.replace("https://target_url/"+profile.userId);
setTimeout(function(){ window.close(); }, 1000);
} else if (liff.getOS() == "android") {
console.log('android系統');
window.location.replace("https://target_url/"+profile.userId);
setTimeout(function(){ liff.closeWindow(); }, 1000);
}
})
.catch((err) => {
console.log('error', err);
});
})
.catch((err) => {
// Error happens during initialization
console.log(err.code, err.message);
});
});
</script>
</head>
<body>
<script src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
</body>
</html>
這兩種形式的跳轉頁面,都會遇到iOS系統上將網頁開啟後,自動關閉開啟頁面的問題,請問有沒有人知道該如何修改才能在iOS系統上能夠在一個畫面中順利跳轉
window.location.replace("https://target_url/"+profile.userId); 改成 location.href = profile.userId; 這樣呢?
関連する質問
関連する質問はありません