4

Is there a way, using Google Sites, to open html links in the same window?

I want to avoid the Buttons Widget because their customization is very limited.

Already tried this and it didn't work

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

And

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

By the way, on Google Sites, when you insert a HTML widget, it will create an IFRAME. I would like to be able to open a link on the same window from this Iframe.

José Paulino
  • 61
  • 1
  • 5

2 Answers2

1

set target value to _self if you want to open the link in the same tab, set it to _blank to open in a new tab or window. I hope you find this useful

Rahal Kanishka
  • 720
  • 13
  • 27
-1

You can open a url in another tab in the browser by click of a button or menu option.

I'm giving the below code which I use for a menu option "Help" which opens a google doc in another tab in same browser window. It works for any browser.

//
//
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
}
//
//



arul selvan
  • 616
  • 4
  • 17
  • I would like to be able to open a subpage on the same window, instead of opening a new tab. As you know Google HTML widgets generates an IFrame. Can you use this Script to open a new page on the window, instead of opening a new tab? – José Paulino Apr 16 '20 at 05:38