Skip to content

Instantly share code, notes, and snippets.

@jleyva
Created November 10, 2023 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jleyva/55bbb772e4b54d4ec2fa5541a5e5acd1 to your computer and use it in GitHub Desktop.
Save jleyva/55bbb772e4b54d4ec2fa5541a5e5acd1 to your computer and use it in GitHub Desktop.
Redirect to launch moodlemobile custom url scheme via parent of iframe
<!DOCTYPE html>
<html>
<head>
<title>Redirect Page</title>
<script>
// Define the target URL
var targetURL = 'moodlemobile://link=https://master.mm.moodledemo.net/course/view.php?id=14';
// Function to redirect the parent window
function redirectParent() {
// Check if the parent window exists
if (window.self !== window.top) {{
// Redirect the parent window to the target URL
window.parent.location.href = targetURL;
} else {
// If the parent window doesn't exist, show an error message
alert('Parent window not found. Redirect failed.');
}
}
// Call the redirectParent function when the page loads
window.onload = redirectParent;
</script>
</head>
<body>
<p>If you are not redirected, <a href="moodlemobile://link=https://master.mm.moodledemo.net/course/view.php?id=14">click here</a>.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment