In your situation, how about the following sample script?
function myFunction() {
const doc = DocumentApp.getActiveDocument();
const selection = doc.getSelection();
if (!selection) return;
selection.getRangeElements().forEach(e => {
const ele = e.getElement();
const type = ele.getType();
if (type == DocumentApp.ElementType.TEXT) {
doc.addBookmark(doc.newPosition(ele, e.getStartOffset()));
} else if (type == DocumentApp.ElementType.INLINE_IMAGE) {
doc.addBookmark(doc.newPosition(ele.asInlineImage().getParent(), 1));
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.