问题
<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