-2

When links are created in Google Docs clicking on them just reveals the URL which one then has to click to actually visit the linked resource. Any way to get any links in a document to simply open when clicked?

Nikko J.
  • 5,319
  • 1
  • 5
  • 14

1 Answers1

1

Place the cursor anywhere in the hyperlink and press Alt + Enter.

or

Use Google Apps Script to open all the links instantly.

Example:

enter image description here

Code:

function findURL() {
  var document = DocumentApp.getActiveDocument().getBody();
  var paragraphs = document.getParagraphs();
  var text = paragraphs[0].getText();
  var child = paragraphs[0].getChild(0).asText();
  //Storing words in an array
  var words = text.match(/\S+/g);
  var results = [];
  //check if array is empty
  if (words) {
    //iterate each words
    words.forEach(word => {
      //use getLinkUrl(offset) to check if the word has link on it.
      if(child.getLinkUrl(child.findText(word).getStartOffset())){
        results.push(child.getLinkUrl(child.findText(word).getStartOffset()).toString());
      }
    })
  }

  openTabs(results);
}

function openTabs(urls) {
  if(!Array.isArray(urls))
    urls = [urls];

  var html = 
    "<script>" + 
      urls.map(function(url) {
        return "window.open('" + url + "');";
      })
      .join('') +
      "google.script.host.close();" + 
    "</script>"; 

  var userInterface = HtmlService.createHtmlOutput(html)
  .setWidth( 90 )
  .setHeight( 1 );

  DocumentApp.getUi().showModalDialog(userInterface, 'Opening...');
}

Output:

enter image description here

Reference:

StackExchange: toddmo's answer on 'How to open multiple urls in different new browser tabs from Google Sheets with a single click?'

Open Existing Spreadsheet via Google App Script

Nikko J.
  • 5,319
  • 1
  • 5
  • 14