Reputation: 13
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...');
}
Upvotes: 1
Views: 1765
Reputation: 50445
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.")
}
}
}
Upvotes: 1
Reputation: 15357
It's not possible for you to force which browser opens a link in Google Apps Script or in JavaScript - this can't be decided by a script, only the end-user that is using the device.
You can however use a conditional that only loads the script if the browser is detected to be Internet Explorer like this though:
function doGet(e){
var browser = HtmlService.createHtmlOutput('index')
var browser2 = browser.getContent();
if (browser2.indexOf('Netscape') !== -1){
if (browser2.indexOf('Trident') !== -1 || browser2.indexOf('MSIE') !== -1){
// run your code
}
return noMessage();
}
else {
return noMessage();
}
}
function noMessage(){
return HtmlService.createHtmlOutput('This page will only run in Internet Explorer.');
}
And the index.html
:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<p id="x"></p>
<script>
document.getElementById("x").innerHTML = navigator.appName + " " + navigator.userAgent;
</script>
</body>
</html>
This just checks the navigator settings for Internet Explorer-like strings and runs the script based on that. It's not a perfect workaround, but sadly forcing the browser like that is simply impossible.
Upvotes: 1