Skip to content

Instantly share code, notes, and snippets.

@jordanrios94
Last active April 18, 2018 13:30
Show Gist options
  • Save jordanrios94/bf20447c18207458b83bf389564123d1 to your computer and use it in GitHub Desktop.
Save jordanrios94/bf20447c18207458b83bf389564123d1 to your computer and use it in GitHub Desktop.
Scrolling Parent Window for iframes
// PARENT WINDOW
(function () {
function scrollWindow(evt) {
var message;
if (evt.origin !== "iframe_URL_HERE" ) {
message = "Action cannnot be performed";
} else {
var x = evt.data.xAxis || 0;
var y = evt.data.yAxis || 0;
window.scrollTo(x,y);
}
}
if (window.addEventListener) {
// For standards-compliant web browsers
window.addEventListener("message", scrollWindow, false);
} else {
window.attachEvent("onmessage", scrollWindow);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment