Javascript - Scroll to bottom on a pop-up window

被刻印的时光 ゝ 提交于 2019-12-11 20:56:57

问题


<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(url,'popUpWindow','height=500, width=800, left=10, top=10, resizable=yes, scrollbars=yes, toolbar=yes, menubar=no, location=no, directories=no, status=yes')
}
</script>


<a href="JavaScript:newPopup('http://www.google.ca');">CLICK HERE</a></a> to go to google.

When the user click on CLICK HERE on the webpage, a pop-up window will appear and it directs you to the http://www.google.ca web page. My question is how do I make it so that the pop-up window will automatically scroll to the bottom on the page when CLICK HERE is clicked?

I found this code segment: window.scrollBy(0,50), but it scrolls the website itself to the bottom. It doesn't scroll the popup window.


回答1:


Try use onload event like this

function newPopup(url) {
    popupWindow = window.open(url,'popUpWindow','height=500, width=800, left=10, top=10, resizable=yes, scrollbars=yes, toolbar=yes, menubar=no, location=no, directories=no, status=yes');
    popupWindow.onload = function () {
        popupWindow.scrollTo(0, popupWindow.document.body.scrollHeight);
    };
}



回答2:


You could try creating an anchor?

<a name="whereYouWantToScrollTo">Click To Scroll To Top</A> 

http://www.webmastercourse.com/articles/anchors/ I'm not sure if you can activate an anchor with JavaScript, but that's the only way I know how to force the user to scroll down on a webpage. Hope this helps



来源:https://stackoverflow.com/questions/25840372/javascript-scroll-to-bottom-on-a-pop-up-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!