Last active
April 18, 2018 13:30
-
-
Save jordanrios94/bf20447c18207458b83bf389564123d1 to your computer and use it in GitHub Desktop.
Scrolling Parent Window for iframes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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