在同一窗口中打开Google Sites的HTML链接

4
有没有一种方法可以在同一个窗口中打开HTML链接,使用Google Sites?
我想避免使用按钮部件,因为它们的自定义非常有限。
已尝试过这个方法,但并没有奏效。
<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在同一个窗口中打开链接。

它应该是 _top - TheMaster
你应该使用 window.postmessage。https://dev59.com/HrTma4cB1Zd3GeqP3Dpm - TheMaster
2个回答

1

如果您想在同一标签页中打开链接,请将目标值设置为_self,如果要在新的标签页或窗口中打开,请将其设置为_blank。希望这对您有所帮助。


我可以在Iframes上使用目标值_self吗? - José Paulino

-1

你可以通过点击按钮或菜单选项在浏览器中的另一个标签页中打开一个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
}
//
//




我想要在同一个窗口中打开子页面,而不是新建选项卡。正如您所知道的那样,Google HTML小部件生成IFrame。您能否使用这个脚本来在窗口中打开一个新页面,而不是新建选项卡? - José Paulino

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接