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

WBOY
Release: 2023-03-03 10:12:02
Original
2197 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!