如何打开给定的网址? [英] How to open a given Url?

查看:26
本文介绍了如何打开给定的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Google Apps Script 与 Google Drive 结合使用,而且我是这方面的初学者.现在,我想在同一窗口中打开给定的 Url.在标准 JavaScript 中,会有open"方法:

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]);

HtmlService 可能是 Google Apps Script 的最佳解决方案.以下代码应在同一窗口中打开 Google 站点:

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>");
}

我打开了 Google Drive 并创建了一个新脚本.以上内容是我在Google Docs Script的编辑器中输入的.但是当我从那里运行这个函数时,什么都不会发生.为什么这样?你能纠正我吗?在新窗口中打开 Google 的代码是什么?

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?

推荐答案

根据 发布 2012 年 10 月 26 日的注意事项 - 您无法再在没有用户交互的情况下自动打开新窗口.

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

打开新窗口以显示这样的 HTML 的最简单方法 -

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>

这篇关于如何打开给定的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆