【问题标题】:Open Google Sites HTML links in same window在同一窗口中打开 Google 协作平台 HTML 链接
【发布时间】:2020-07-29 05:33:31
【问题描述】:

有没有办法使用 Google 协作平台在同一窗口中打开 html 链接?

我想避免使用 Buttons Widget,因为它们的自定义非常有限。

已经试过了,还是不行

<a href="https://www.google.com" target="_PARENT">Google.com</a>

<a href="" onclick="Window.open('https://www.google.com','_parent')" >Google.com</a>

顺便说一句,在 Google 协作平台上,当您插入 HTML 小部件时,它会创建一个 IFRAME。我希望能够从此 iframe 在同一窗口上打开一个链接。

【问题讨论】:

标签: javascript html google-apps-script google-sites google-sites-2016


【解决方案1】:

如果您想在同一选项卡中打开链接,请将目标值设置为_self, 将其设置为 _blank 以在新选项卡或窗口中打开。我希望你觉得这很有用

【讨论】:

  • 我可以在 iframe 上使用目标值 _self 吗?
【解决方案2】:

您可以通过单击按钮或菜单选项在浏览器的另一个选项卡中打开网址。

我给出了下面的代码,用于菜单选项“帮助”,它在同一浏览器窗口的另一个选项卡中打开一个谷歌文档。它适用于任何浏览器。

//
//
function openUrl( url ){
  var html = HtmlService.createHtmlOutput('<html><script>'
  +'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
  +'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
  +'if(document.createEvent){'
  +'  var event=document.createEvent("MouseEvents");'
  +'  if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'                          
  +'  event.initEvent("click",true,true); a.dispatchEvent(event);'
  +'}else{ a.click() }'
  +'close();'
  +'</script>'
  // Offer URL as clickable link in case above code fails.
  +'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. <a href="'+url+'" target="_blank" onclick="window.close()">Click here to proceed</a>.</body>'
  +'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
  +'</html>')
  .setWidth( 90 ).setHeight( 1 );
  SpreadsheetApp.getUi().showModalDialog( html, "Opening ..." );
}
//
//
function open_help(){
 openUrl("https://docs.google.com/document/d/..../edit");//this is the help file Google Doc
}
//
//



【讨论】:

  • 我希望能够在同一窗口中打开子页面,而不是打开新标签。如您所知,Google HTML 小部件会生成一个 IFrame。您可以使用此脚本在窗口上打开一个新页面,而不是打开一个新选项卡吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-26
  • 1970-01-01
相关资源
最近更新 更多