Use Google App Script to prevent user opening url link in Sheets if site is already open in another browser tab - google-apps-script

I've got a Google Sheet that contains numerous hyperlinks.
I'd like to prevent the user from opening multiple instances of the same site.
ie. user clicks the hyperlink in one cell which opens the linked site in a new tab, then attempts to click the same hyperlink while the first new tab is still open - I'd like a dialogue box to appear saying that they cannot open this second new tab until they have closed the first one.
Is this possible via Google App Script?
Many thanks!

Unfortunately not. GAS has no access to your browser data and cannot know what tabs are open.Moreover, GAS has no way of intercepting hyperlink clicks from within a spreadsheet, it can only do that in a side bar, modal (or modeless) dialog, a custom or an add-on menu or an image with a script attached to it.

Related

Google Sheets script : Click on menu item

I'd like to have a script that simply clicks on File > Download > PDF of a Google Sheets menu.
To simplify, I first tried to have the script click on "File".
With devtools I could determine that this menu item has id="docs-file-menu" so my function should look like :
document.getElementById('docs-file-menu').click();
But it doesn't work because document is not defined.
While searching for a solution, I understood that Apps scripts cannot interact with the browser, but I'm not quite sure whether that includes the sheets menus items as well?
Is there any way to make a script click on a menu item?
If not possible, is there any other way to make the "download as pdf" window appear?

Open Chrome tab through Google Apps Script

I'm trying to open a new tab in Chrome via Google Apps Script.
My trigger is From spreadsheet - On form submit
Is it possible?
Thanks
This is not possible. Your trigger is executed on form submit. Someone could submit the form without having the Spreadsheet open. So where would the new Chrome window/tab open?
You can have a sidebar in a Google Sheet that can open a new window/tab but that requires human interaction. Meaning, the user would need to go to the Spreadsheet, click on something to load/open the sidebar, and then click a button that would open a new Chrome window/tab.

Activating script via button press on embedded Google Sheet

I am trying to embed a Google Spreadsheet that has a script I'd like users to be able to activate. I don't want them to be able to edit anything on the page.
I thought I could do this by
Share sheet and set to edit permissions
Restrict editing on the one sheet I want to share (the images sit above the cells, so I thought this would prevent people from editing cells but allow them to click on the button
Publish to the web
Embed the sheet
Here is the iframe I used:
<iframe width="1250" height=1000 src="https://docs.google.com/spreadsheets/d/e/2PACX-1vRRajy1TK9Y9YQg-Df3bwTy9ktxPECq6T5gS7UfkrYpV_osxwDwRuQClC168B8-o4KsCdFl4kfMYtau/pubhtml?gid=1796260078&single=true&widget=true&headers=false"></iframe>
For context the scripts hide or show different rows. Clicking "show game 2" hides a section of rows and "show game 1" unhides these rows.
The sheet embeds okay but isn't interactable. I have turned off the restricted editing to test (it's back on) and that didn't allow people to edit anything, so I am not sure what I am doing wrong here.
Any help would be greatly appreciated! Cheers!
Workaround:
Use a another button outside the embedded spreadsheet instead.
Publish a headless web-app from your sheet using doPost()
On Button click, use JavaScript to post from your website to apps script web-app
On receiving post request, hide/show the rows using your original script.
References:
Web-app

How do you get the url of the script your running in Google scripts?

If your making a script using the Google script editor, how do you get the url of the script your running in the google script editor in google docs? (sorry for not capitalizing the word google)
If I'm understanding your question, you can choose the "Publish" -> "Deploy As a Web App..." menu item. From there, the pop-up will show "Deploy as Web App" with a text box underneath containing the URL. Grab that (or click the "latest code" link just below it). You don't have to follow-through on the re-deploy (if you do, you'll want to use the URL it presents in a pop-up after doing so)
If you haven't previously deployed it, you'll need to save a "version" and deploy it, as touched on here. Upon doing that, it will present you with the Url in a pop-up as mentioned above. If you miss it, the the first part of this answer applies.

How to dynamically change the spreadsheet of a Google site page?

I've checked this issue and now I know (with getHtmlContent and setHtmlContent) how to create a webapp that :
a) takes into account the active user id
b) selects accordingly the right spreadsheet to be displaid
c) adapts a Google site page with the selected spreadsheet
But my problem is that I want to dynamically adapt the page when the user clicks the link to it (from navigation area). How can I trigger my webapp ?
Thanks for the help !
I don't think it is possible to invoke scripts from links in the Navigation area. But it is definitely possible to invoke an Apps Script on a link in the content area of a Google Sites page.
You can consider invoking your script from such a link