Skip to content

Instantly share code, notes, and snippets.

@ajtransak
Created February 6, 2025 06:07
Show Gist options
  • Save ajtransak/473651ed41fc464d9d9bf2fcc810ad22 to your computer and use it in GitHub Desktop.
Save ajtransak/473651ed41fc464d9d9bf2fcc810ad22 to your computer and use it in GitHub Desktop.
Transak IFRAME Logout Events
<!-- This code embeds a Transak iframe in a webpage and provides a "Logout" button that,
when clicked, sends a postMessage event to the iframe to request a logout. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Transak Iframe Logout</title>
</head>
<body>
<div
style="
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
justify-content: center;
"
>
<iframe
id="transak-iframe"
title="Transak"
src="https://global-stg.transak.com/?apiKey=a2374be4-c59a-400e-809b-72c226c74b8f"
allow="camera;microphone;fullscreen;payment"
style="height: 650px; width: 400px; border: none"
></iframe>
<button
id="logout-btn"
style="
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
"
>
Logout
</button>
</div>
<script>
document.getElementById("logout-btn").addEventListener("click", () => {
document
.getElementById("transak-iframe")
.contentWindow?.postMessage(
{ event_id: "TRANSAK_LOGOUT_USER_REQUEST" },
"*"
);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment