Search code examples
javascriptgoogle-apps-scriptweb-applications

How to open a given Url?


I am using Google Apps Script with Google Drive, and I am a very beginner in this matter. Now, I would like to open a given Url in the same window. In standard JavaScript, there would be the 'open' method:

var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);

Probably, HtmlService would be the best solution with Google Apps Script. The following code should open the Google-site in the same window:

function doGet() {
     return HtmlService.createHtmlOutput(
     "<form action='http://www.google.com' method='get' id='foo'></form>" + 
     "<script>document.getElementById('foo').submit();</script>");
}

I opened Google Drive and created a new script. I typed in the above content in the editor of Google Docs Script. But when I am running this function from there, nothing at all will happen. Why so? Could you correct me? And what would be the code for opening Google in a new window?


Solution

  • Per the Release Notes for Oct 26, 2012 - you can no longer auto open a new window without user interaction.

    The simplest way to open a new window to show an HTML like this -

    <a href='http://www.google.com' target='_blank'>Open in new window</a>