是否可以使用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在同一窗口上打开链接。
您可以通过单击按钮或菜单选项来在浏览器的另一个选项卡中打开URL。
我给出了以下代码,我将其用于菜单选项“帮助”,该选项将在同一浏览器窗口的另一个标签中打开一个Google文档。它适用于任何浏览器。
//
//
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
}
//
//
如果要在同一标签中打开链接,请将目标值设置为_self
,将其设置为_blank
以在新标签或窗口中打开。希望您觉得这有用