Scroll to Top on Google Docs

355 views
Skip to first unread message

Julie Blalock

unread,
Feb 1, 2022, 12:38:39 PM2/1/22
to Google Apps Script Community
I am wanting to run a "scroll to top" button on google docs. Is that possible? I have a code but it comes up with ReferenceError: $ is not defined. I am not a coder and understand very little in the scripts. Can someone help me figure this out?

Edward Ulle

unread,
Feb 1, 2022, 6:06:22 PM2/1/22
to Google Apps Script Community
Not sure how you intend to trigger it but this will put the cursor at the top.  I used a menu option.

function test() {
  try {
    var doc = DocumentApp.getActiveDocument();
    var body = doc.getBody();
    var paras = body.getParagraphs();
    var position = doc.newPosition(paras[0],0);
    doc.setCursor(position);
  }
  catch(err) {
    DocumentApp.getUi().alert(err);
  }
}

Reply all
Reply to author
Forward
0 new messages