Google Apps Script to open a URL
You can build a small UI that does the job like this :
function test(){
showURL("http://www.google.com")
}
//
function showURL(href){
var app = UiApp.createApplication().setHeight(50).setWidth(200);
app.setTitle("Show URL");
var link = app.createAnchor('open ', href).setId("link");
app.add(link);
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
If you want to 'show' the URL, just change this line like this :
var link = app.createAnchor(href, href).setId("link");
EDIT : link to a demo spreadsheet in read only because too many people keep writing unwanted things on it (just make a copy to use instead).
EDIT : UiApp was deprecated by Google on 11th Dec 2014, this method could break at any time and needs updating to use HTML service instead!
EDIT :
below is an implementation using html service.
function testNew(){
showAnchor('Stackoverflow','http://stackoverflow.com/questions/tagged/google-apps-script');
}
function showAnchor(name,url) {
var html = '<html><body><a href="'+url+'" target="blank" onclick="google.script.host.close()">'+name+'</a></body></html>';
var ui = HtmlService.createHtmlOutput(html)
SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
}
Google Apps Script to open a URL based on a cell
From I would like to use that cell as a reference to my script (which opens url on a button).
and How can I modify this script in order to get the link from the B2 cell?
, when your script is modified, how about the following modification?
From:
function openUrl( url="https://google.com" ){
To:
function openUrl(){
var url = SpreadsheetApp.getActiveSheet().getRange("B2").getValue();
References:
- getRange(a1Notation)
- getValue()
How to programmatically (via AppsScript) open a specific Sheet in a Google Spreadsheet via URL
This function requires you to paste the url into a prompt. It will open up the spreadsheet by url and get all the data on the current sheet and display it in a dialog and at the end it will display the name of the sheet.
function getData() {
const ui = SpreadsheetApp.getUi();
const r = ui.prompt('Url Dialog', 'Enter Url', ui.ButtonSet.OK_CANCEL);
if (r.getSelectedButton() == ui.Button.OK) {
const url = r.getResponseText()
const ss = SpreadsheetApp.openByUrl(url);
let id = url.slice(url.indexOf("=") + 1);
let sh = ss.getSheets().filter(sh => sh.getSheetId() == id)[0];
let vs = sh.getDataRange().getDisplayValues();
let s = '<textarea cols="50" rows="12"> ';
vs.forEach((r, i) => {
if (i > 0) {
s += ['\n'];
}
s += r.join(',');
})
s += `\nSheet Name: ${sh.getName()}</textarea>`
ui.showModelessDialog(HtmlService.createHtmlOutput(s).setWidth(800), 'Title');
}
}
Url Dialog:
Data Dialog:
Scroll down to the bottom to see the sheet name.
App Script - Open Url in new Tab from Google WebApp (without assigned Spreadsheet)
Get url from app script and open spreadsheet in new tab wit JavaScript
Update app script function
function clickEvent () {
const lock = LockService.getScriptLock();
lock.tryLock(5000);
if (lock.hasLock()){
var email = Session.getActiveUser().getEmail();
lock.releaseLock();
return createFile(email);
}
}
Also update JavaScript Code
function sendRequest(){
google.script.run.withSuccessHandler(
function (link) {
window.open(link, '_blank').focus();
}
).testCSV3();
}
Reference: Communicate with Server Functions
Open a link in Google Document with one click using google apps script
A script can only allow you to perform actions for which the endpoint is implemented in the UI
Given that the UI of Google Documents is set up in a way that after clicking on a link text you have to click a second time on the actual URL showing up - unfortunately there is no way to modify this default behavior programmatically.
Google Script for opening a URL in dedicated browser (Internet Explorer) by click in Spreadsheets
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.")
}
}
}
unshorten ow.ly URL in Google Apps Script
In your question, https:// ow . ly /d9AV30jRJWJ
is used (Spaces are included because of avoiding the error of Stackoverflow.). But, I thought that in this case, it might be http:// ow . ly /d9AV30jRJWJ
. Because when I accessed https:// ow . ly /d9AV30jRJWJ
, no response is returned. On the other hand, when I accessed http:// ow . ly /d9AV30jRJWJ
, the blog page is returned. If my understanding is correct, how about the following modification?
Modified script:
function ExpandURL(url) {
url = /https?:\/\//.test(url) ? url : "https://" + url; // Modified
var response = UrlFetchApp.fetch(url, { followRedirects: false });
var longurl = decodeURIComponent(response.getHeaders()['Location']);
return longurl;
}
function test() {
Logger.log(ExpandURL("http:// ow . ly /d9AV30jRJWJ")) // When you test this, please modify ` ow . ly ` to `ow.ly`.
}
- When this
test
is run,https://blog.leadquizzes.com/ubersuggest-find-profitable-keywords-with-neil-patels-free-seo-tool?platform=hootsuite
is returned.
Related Topics
How to Prevent Newline At the End of HTML Input Field
Call Method from HTML Only One Time in Angular2
Responsive Fullscreen Youtube Video With No Black Bars
Make Content Horizontally Scroll Inside a Div
Fixed Position Relative to Parent Container
How to Prevent Desktop Browser (Chrome, Safari) from Zooming a Webpage
How to Type Text With Hat "^" in HTML
How to Make All Images of Different Height and Width the Same Via CSS
How to Remove Outline in Bootstrap 4
Limit the Size of a File Upload (Html Input Element)
How to Remove Free Spaces Between Divs
Selecting an Option in a Dropdown List Using Request Parameters
Using Mailto to Send Email With an Attachment
Is It Valid to Replace Http:// With // in a ≪Script Src="Http://..."≫
Line Break in HTML Select Option
Css When Inline-Block Elements Line-Break, Parent Wrapper Does Not Fit New Width
How to Set Max-Length in an Html5 "Input Type=Number" Element