Javascript弹出滚动跳转
当然有一个简单的方法可以做到这一点。我需要在 java 脚本弹出窗口中加载页面。但我需要在窗口中显示的内容位于页面下方。有没有办法跳转到页面的该部分? (那么跳转到垂直滚动坐标?)(另外,我无法编辑正在显示的页面。仅是其链接)
非常感谢任何帮助!
Surely there is an easy way to do this. I need to load a page in a java script popup window. But the content I need to show in the window are a ways down the page. Is there a way to jump to that part of the page? (So jump to a vertical scroll coordinate?) (Also, I cannot edit the page which is being shown. Merely the link to it)
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是通过在 url 中的哈希值后面附加其 id 来链接到页面上的元素。即,当打开弹出窗口时,
其中“要显示的元素”是页面下方元素的 id。
The easiest way would be to link to an element on the page by appending its id after a hash in the url. ie, when openinging your popup,
where "element-to-show" is the id of the element that is down the page.
使用 HTML 锚点并在弹出窗口中加载
page.html#myanchor
(而不仅仅是page.html
)。http://www.w3.org/TR/html4/struct/links.html
Use HTML anchors and load
page.html#myanchor
in the popup (instead of justpage.html
).http://www.w3.org/TR/html4/struct/links.html
假设您无法链接到锚点,但加载到弹出窗口中的页面位于同一域中,您可以使用类似以下内容:
您可能需要对此进行自定义,例如,您可以向 openInPopUp() 提供一个附加参数,其中包含要滚动到的确切位置。
代码如下:
如果您想从调用页面之外的其他域加载内容,这将不起作用,但会导致权限错误。
scrollTo 函数的详细信息
Assuming you can't link to anchors but the page you load into the popup is in the same domain you could use something like this:
You may want to customize this, e.g. you could provide an additional parameter to openInPopUp() with the exact position to scroll to.
Here's the The Code:
If you want to load content from another domain, than the calling page, this won't work but end in a permissions error.
Details for the scrollTo function