Home  >  Article  >  Backend Development  >  javascript - How to bring the content of the iframe back to the top outside the iframe

javascript - How to bring the content of the iframe back to the top outside the iframe

WBOY
WBOYOriginal
2016-12-05 13:44:222152browse

javascript - How to bring the content of the iframe back to the top outside the iframe

As shown in the picture, how to click the go top button outside the iframe to make the content in ​​the iframe return to the top. I tried several times but it doesn’t work. Is there anyone who has done it?
The premise is that the iframe page cannot be modified.

Reply content:

javascript - How to bring the content of the iframe back to the top outside the iframe

As shown in the picture, how to click the go top button outside the iframe to make the content

in ​​the iframe return to the top. I tried several times but it doesn’t work. Is there anyone who has done it? The premise is that the iframe page cannot be modified.

If it is not cross-domain, it can be as follows

<code>var iframeElement; // 自己选择iframe
iframeElement.contentWindow.scrollTo(0, 0);</code>

I have no solution for cross-domain issues

DEMO

Register the slide to top method in the document of the iframe. When the external page triggers a click event, it first finds the iframe and then calls this method

Did you do it on the local page? That doesn’t work, try setting up a server

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn