I'm looking for a way to automatically scroll to the bottom of a Google doc every time I open it. Something functionally equivalent to this answer would be great.
3 Answers
From my answer to Move to last line of Google Document when it is opened
Try this
function onOpen(){ var doc = DocumentApp.getActiveDocument(); var body = doc.getBody(); var numChildren = body.getNumChildren(); var pos = doc.newPosition(body.getChild(numChildren - 1),0); doc.setCursor(pos); }
The only way I'm familiar with doing this automatically is to put a bookmark at the end of the document and open up that document by navigating straight to that bookmark's URL.
Shortcuts to go to the end of the end of the document are
- Windows: Ctrl + End
- Macs: Command + End
- Chromebooks: Ctrl + Search + Right arrow
You can also hold Shift and click the scrollbar to jump to a section on the page. But I don't know if there's any way to do this once the Google Doc is fully loaded.
this script should work with Google Docs document:
var file = SpreadsheetApp.getActiveSpreadsheet(); var sheet = file.getActiveSheet(); var row = LineToScrollTo; file.setActiveCell(sheet.getRange(row,1));
-
1Do you mean through "Tools" -> "Script editor"? Pasting that into there doesn't seem to work for me but I've never used that function before so I very well could be doing something wrong. Attempting to create a trigger on document open doesn't seem to work for me. Commented Apr 25, 2019 at 20:20
-
1I went through Tools -> Script editor and pasted this script, and it didn't work. I also tried nesting the script inside an
onOpen(e) { }
block, and it didn't do anything. @user0, did you test this successfully on a Google doc? Commented Apr 26, 2019 at 16:06