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?
            Asked
            
        
        
            Active
            
        
            Viewed 747 times
        
    1 Answers
1
            
            
        Place the cursor anywhere in the hyperlink and press Alt + Enter.
or
Use Google Apps Script to open all the links instantly.
Example:
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:
Reference:
        Nikko J.
        
- 5,319
 - 1
 - 5
 - 14
 

