I would like to update the link of my google Form in the HTML code of the spreadsheet's sidebar automatically when the spreadsheet is copied since the form is also copied and linked to the new spreadsheet. I cannot use the same Form for this application.
Script to display the sidebar
//@OnlyCurrentDoc
function onOpen() {
SpreadsheetApp.getUi().createMenu("👉blablabla👈").addItem("blablabla", "showSidebar").addToUi();
}
function showSidebar() {
SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile("Sidebar.html").setTitle("Remplir formulaire"));
}
HTML code:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<iframe src="https://docs.google.com/forms/xxxxxxxxxxxx" width="100%" height="595" frameborder="0" marginheight="0" marginwidth="0">Chargement…</iframe>
</body>
</html>
I'm investigating to copy the URL from a random cell of the spreadsheet using the following script:
function GetUrlForm() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
return ss.getFormUrl();
}
but i can't get anything out of this. I've explored the "window.location" but I am not good enough to know how to use it.
I am really new to programming and any help would be really appreciated. I can drastically change the code wothout any problem if needed.
Thank you kindly !
Looks like you want to update the src parameter of the iframe. I recommend you to add an id attribute to the iframe in your HTML to make it easier to reference.
<iframe id="myId" src="https://docs.google.com/forms/xxxxxxxxxxxx" width="100%" height="595" frameborder="0" marginheight="0" marginwidth="0">Chargement…</iframe>
Then you can update the src parameter of the iframe after your retrieve the URL, this will automatically reload the frame.
function updateFrame(src){
document.getElementById("myId").src = src;
}
You can see: https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/src