Reputation: 263
I have a certain page which holds a iframe and gets submitted and then a new message is shown within the iframe, this is a lot shorter then the iframe before so it doesn't go to the point I want it on the page.
Now I want to scroll to the new id using jQuery meaning the user can read it from the top and not have to scroll.
My id of my iframe is "#iframe-container
".
if (window.location.pathname.split('/')[1] == "Test.aspx")
{
// jquery here.
}
thanks
Upvotes: 0
Views: 100
Reputation: 183
Cross-window post message API support to communicate to new domain . using post message method.
In iframe page
iframe.contentWindow.postMessage("your message",iframe.src);
source page:
if (window.addEventListener) {
window.addEventListener('message', function (e) {
if(e.data =="yourmess age"){
$(window.parent.document).scrollTop();
}
Upvotes: -2
Reputation: 11137
$("html, body").animate({ scrollTop: $('#iframe-container').offset().top }, 1000);
You can change 1000 to be less to scroll faster or even to 0 to jump to the ID directly.
$("html, body").animate({ scrollTop: $('#iframe-container').offset().top }, 0);
Upvotes: 4