How to open a URL link from JavaScript inside a Google Apps Script HTML Google Site Gadget

google apps script url parameters
google script open url
google script open html
open url in google sheets
google script open file by url
google sheets button to open url
google app script redirect url
google apps script open file

I have written an HTML (not UI) gadget in Google Apps Script to be embedded in a Google Site. The gadget presents a drop-down with options that contain URL/display name value/text pairs.

I want to put a button in the gadget that opens a new window corresponding to the selected URL. But, basically, I get an "Object does not contain an 'open' method" error when I execute;

Is there a way around this? I can (and have) created gadgets with anchor tags that successfully open other windows, but doing this same action from javascript appears to not be allowed.

Anything that accomplishes the functionality is fine. A jQuery-based solution would be great.


Due to Caja’s sanitization, all the javascript functions are not supported that's why can't open a new window in App Script.

The workaround to display a popup in App Script is to use an overlay window(which is not a popup technically but appears like a popup) like jQuery modal dialog which are supported in App Script.

However iframe tags are not supported in App Script, so an attempt to open a url in modal window with the help of iframe tags will not work.

You can read more about these restriction in App Script from the link below :**

Hope it helps!

Web Apps | Apps Script, I have written an HTML (not UI) gadget in Google Apps Script to be embedded in a Google Site. The gadget presents a drop-down with options that contain  google.script.url is an asynchronous client-side JavaScript API that can query URLs to obtain the current URL parameters and fragment. This API supports the google.script.history API. It can only be used in the context of a web app that uses IFRAME. It is not intended for use with sidebars and dialogs in an add-on or container-script context.

You can open the link directly by running the JS in a dialog using the HTMLService.

Here's a demo sheet (take a copy to see the script).

openNewWindow() is assigned to the button.

function openNewWindow() {

  var htmlString = 
    '<div>' + 
      '<input type="button" value="Close" onclick="" />' + 
    '</div>' +

  var htmlOutput = HtmlService

    .showModalDialog(htmlOutput, 'Opening New Window...');  

Insert websites and Apps Scripts using iFrames, Requirements for web apps; Request parameters; Deploying a script as a web app The function returns an HTML service HtmlOutput object or a Content service TextOutput object. The second is the link labeled latest code and ends in /dev . Open the Sites page where you'd like to add the web app. This is a sample script for opening a site with new window using Google Apps Script. It is possible to open the site inside the opened dialog box using iframe. But in my situation, I had to open the site as new window. So I created this. As a sample application, it can think of like this.

It's not possible to do that because of caja sanitization. The options bellow will not work.

1) jquery - $("#some_link_id").click() 2) javascript -, window.href, etc...

The only workaround but I guess that will not fit to your problem is creating links with target="_blank" to open new windows but as I said is not possible to click in these links though javascript/jquery.

<a href="" id="my_link" class="abc" target="_blank">My Link</a>

Insert HTML, JavaScript and CSS - new Google Sites, Insert HTML, JavaScript and CSS - new Google Sites to see the full page inserted in your site or the Preview option if you want to see a link card. New Google Sites - Insert Google Apps Scripts Web Apps.webm If you interested in knowing more about these Apps Script gadgets for new Google Sites, or want your own  Gets the URL for a favicon link tag added To resize a dialog that is already open, call google.script Meta tags included directly in an Apps Script HTML file

I was able to achieve this using a form. On submit, set the action of the form to the desired URL, as determined by the selected item in the select box.

    <script src="//"></script>
       $('#yourForm').attr('onsubmit',null); //set onsubmit to Null for NATIVE Caja sandboxmode

          var val = $('#yourSelect').val();  //get value of select box
          $('#yourForm').attr('action',val); //set action of form
    <select id="yourSelect">
       <option value="">Google</option>
       <option value="">Bing</option>

    <form id="yourForm" method="get" target="_blank" action="">
    <input type="submit" value="Open Selected">


Add gadgets, scripts & more to classic Sites, Important note: this feature is far better than HTML Box in classic Google Sites as it is less restrictive Apps Scripts Gadgets developed for new Google Sites  Many web developers recommend loading JavaScript code at the bottom of the page to increase responsiveness, and this is even more important with the HTML service. Moving your <script> tags to the end of your page will let HTML content render before the JavaScript is processed, allowing you to present a spinner or other message to the user.

Is Apps Script embeddable in New sites?, You can customize your site by adding links, scripts, gadgets, app content, and other features. Customize your site. Link to files or text. You can link to files or  To add an HTML file to your Apps Script project, open the Script Editor and choose File > New > Html File. Within the HTML file, you can write most standard HTML, CSS, and client-side JavaScript. The page will be served as HTML5, although some advanced features of HTML5 are not available, as explained in Restrictions.

Google Apps Hacks, Is it possible to embed an app scripts project in new sites? If yes, will scripts like'URL','_top') still work correctly? Embed Websites and Apps Scripts Gadgets using iframes HTML Service: Restrictions question is why do you want to use javascript to open the link instead of just a link? On a computer, open a site in classic Google Sites. Go to the page you want to edit. Click Edit . Click where you want to insert the script. Click Insert Apps Script. Follow the instructions in the window. Option 2: Add as a link. Run your script when someone signed in to their Google Account clicks a link. On a computer, open a site in classic

Add JavaScript Widget to Google Site using App Script, Plus, you can convert any feed to an iGoogle home page gadget. your calendar feed URL to add it to your personalized Google home page, as shown in Figure 7-19. First, there's the HTML opening portion, including the document type Furthermore, there's a link to Google's JavaScript library; it includes your unique  Remember the URL (link location) at which the gadget is hosted and accessible. At Google Sites, browse to web page to include the gadget, and click Edit page button. Place the mouse pointer at where the gadget (content, JavaScript or ad) to be inserted. Click on Insert from the menu bar.