google-apps-scripturlgoogle-chrome-extensiongoogle-drive-api

In a Google Drive folder, have an external URL stored as a "file" that when clicked opens an external website


Problem: I am trying to figure out if there is a way to store urls in a Google Drive Folder alongside other files. When you click on the url "file" to open the file from Google Drive, Google Drive would instead open the URL in a new tab

Example: For example, I've created a Google Doc that has a URL within the Google Doc - see screenshots below.

Google drive test folder

Google drive doc with url in it

My desired behavior is to double click on the Google Doc, and instead of loading the Google doc load the URL within the Google Doc (www.spotify.com) in a separate window.

Clarification: I don't need to use Google Docs, so if there is some other filetype, extension, or workaround that allows you to open a URL from a Google Drive Folder that would solve this as well.

My steps that I've taken so far: So far I've taken a look in the Chrome Store and read through some of the Google Drive help documentation. I did find this article on handling an open URL in the Google Drive documentation but can't determine whether this is relevant.

Thanks in advance for any ideas you might have!


Solution

  • Issue and workaround:

    I think that in the current stage, your goal cannot be directly achieved. So it is required to use a workaround. For example, how about the following workaround?

    In this workaround, as a sample, a dialog of Google Document is used. When a Google Document is opened, a dialog is opened. By this, the page is opened the URL by Javascript. When this is reflected in the sample script. it becomes as follows.

    Sample script:

    Please copy and paste the following script to the script editor of Google Document. And, please install OnOpen trigger to the function myFunction. By this, when Google Document is opened, the dialog is automatically opened and Javascript is run, and then, the URL is opened.

    function myFunction() {
      var url = "###"; // Please set URL.
    
      var html = HtmlService.createHtmlOutput(`<script>window.open('${url}', '_blank');google.script.host.close()</script>`)
      DocumentApp.getUi().showDialog(html);
    }
    

    Note:

    Reference: