Skip to content

Commit

Permalink
Cover the case when the current frame is also the parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammadk committed Jan 6, 2017
1 parent e2ae588 commit 644a3eb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/shopify_app/login_protection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,23 @@ def redirection_javascript(url)
<html lang="en">
<head>
<meta charset="utf-8" />
<base target="_top">
<title>Redirecting…</title>
<script type="text/javascript">
data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: window.location.origin + #{url.to_json} }
});
window.parent.postMessage(data, "https://#{sanitized_shop_name}");
// If the current window is the 'parent', change the URL by setting location.href
if (window.top == window.self) {
window.top.location.href = #{url.to_json};
// If the current window is the 'child', change the parent's URL with postMessage
} else {
data = JSON.stringify({
message: 'Shopify.API.remoteRedirect',
data: { location: window.location.origin + #{url.to_json} }
});
window.parent.postMessage(data, "https://#{sanitized_shop_name}");
}
</script>
</head>
<body>
Expand Down

0 comments on commit 644a3eb

Please sign in to comment.