아래의 코드를 gemini가만들어줌.
<h1> 카톡브라우저 빠져나가는 중...</h1>
<script>
// 외부 브라우저로 열고자 하는 YouTube URL
const TARGET_URL = " 여기에 누리집주소를 넣어주세요. ";
function openExternalBrowser() {
const userAgent = navigator.userAgent.toLowerCase();
// 1. 카카오톡 내부 브라우저인지 점검
if (userAgent.includes('kakaotalk')) {
console.log("카카오톡 내부 브라우저임. 외부 브라우저로 바꿀 것임.");
// 2. 외부 브라우저로 전환
// URL을 안전하게 인코딩하는 것이 중요해요
const redirectUrl = `kakaotalk://web/openExternal?url=${encodeURIComponent(TARGET_URL)}`;
// 방향 바꾸기 실행
window.location.href = redirectUrl;
} else {
console.log("외부 브라우저입니다. 바로 지정하신 주소로 이동합니다.");
// 카카오톡 내부 브라우저가 아닌 경우, 즉시 지정하신 주소로 이동
window.location.href = TARGET_URL;
}
}
// 페이지가 완전히 실행된 후 함수 실행
window.onload = openExternalBrowser;
// 혹시 모를 경우를 대비
document.addEventListener('DOMContentLoaded', openExternalBrowser);
</script>