Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

javascript - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...