简体   繁体   中英

Jump to top of parent from iframe - cross domain

I have an iframe that is a bit long that I want to jump up to the top of the page once the submit button is pressed (I'm using ASP.NET and a new panel shows within the iframe once the form is submitted). The problem is my iframe is on a different domain than my parent page. Here's what I have so far:

In iframe:

<script>
function scrollWindow(){
        window.top.scrollTo(0,0);
}
</script>
<input type="submit" onclick="scrollWindow();" value="Submit Request">

This works if the parent and iframe are on the same domain, but not cross domain.

If the page within the iframe is changing when you press submit you should be able to use the "onload" event of the iframe to trigger the scrolling.

It's a hack, and you should feel bad about doing it. It should work though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM