Search code examples
google-apps-scriptgoogle-sheetsweb-applications

Google Script for opening a URL in dedicated browser (Internet Explorer) by click in Spreadsheets


I am using Google Chrome (as G-Suite is used by the users for standard/collaboration processes) and I am looking for a Google Script that opens a URL out of Google Spreadsheet in a new internet explorer application.

Background: I have a Google Sheets document with lots of tabs. The first tab is the "landing page", linked to the tabs and to external Google Documents or other URLs, using macros / Google Script. The problem is that I have one online application that only runs in Internet Explorer. So I need to have a script forcing to open the URL in a new Internet Explorer application. Everything I found was on how to open a new window or tab, but I did not find anything saying "open a url in a dedicated browser" (here: Internet Explorer). I am looking for something like the script below, I used for opening external links out of Google Spreadsheets, but additionally saying "do this with Internet Explorer":

function open link in new window() {
var js = " \
<script> \
window.open('https://www.externalwebapplicationthatonlyrunsonwindowsexplorer.com', '_blank', 'width=800, height=600'); \
google.script.host.close(); \
</script> \
";
var html = HtmlService.createHtmlOutput(js)
.setHeight(10)
.setWidth(100);
SpreadsheetApp.getUi().showModalDialog(html, 'Loading, please wait...');
}

Solution

  • Although it's not possible to force open links in specific browser, it is possible to detect the user agent string as the previous answer states. You can use use HtmlService.getUserAgent():

    function testInternetExplorer(){
      var html = HtmlService.createHtmlOutput(js)
        .setHeight(10)
        .setWidth(100);
      var ui = SpreadsheetApp.getUi();
      var response = ui.alert('This app link is available only on Internet Explorer.\n Proceeding to use outdated browsers may cause serious damage to your device, data  and privacy.\nAre you sure you want to continue?', ui.ButtonSet.YES_NO);
      if(response == ui.Button.YES) {
        if(/Trident|MSIE/.test(HtmlService.getUserAgent())){
         ui.showModalDialog(html, 'Loading, please wait...');
        } else { 
         ui.alert("Internet Explorer is not detected.\n Cannot proceed.")
        }
      }
    }