![](/img/trans.png)
[英]javascript crossbrowser determine if user scrolld to the bottom of page
[英]Sent user to page bottom by javascript
我正在嘗試將用戶發送到頁面底部
通過javascript
我正在嘗試此代碼
window.scrollTo(0,document.body.scrollHeight);
這是行不通的
但是如果我嘗試
window.scrollTo(0,9999999999999999);
效果很好
頁面高度可以大於9999999999999999
嗎?
還是有更好的方法?
嘗試這個:
document.body.scrollTop = document.body.scrollHeight;
document.documentElement.scrollTop = document.documentElement.scrollHeight;
您始終可以將它們發送到Number.MAX_VALUE
,這保證是最大可能的。
對於在Selenium中向下滾動,請使用以下代碼:
JavascriptExecutor jse = (JavascriptExecutor) driver;
// (driver is your browser webdriver object)
jse.executeScript("window.scrollBy(0,document.body.scrollHeight || document.documentElement.scrollHeight)", "");
要向上滾動,請使用以下代碼:
jse.executeScript("window.scrollBy(0,-document.body.scrollHeight || -document.documentElement.scrollHeight)", "");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.