google-apps-scriptgoogle-sites-2016

Trying to create a google script to generate a floating button for New Sites


I'm trying to create a floating button to a charity website, encouraging people to 'donate'. The idea is the button remains visible at all times, on all pages, when you scroll down. I've created a button that works using the w3schools tool, but cannot get it work on New Google Sites (which is what the site is built in). If I embed it, it puts the button in an iFrame, not on the main site. I was hoping that creating a google Script would allow me to add it, but don't know where to start in converting the current code to a google script. Any advice very gratefully received!

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 20px;
}

#myBtn {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 30px;
  z-index: 99;
  font-size: 18px;
  border: none;
  outline: none;
  background-color: #660000;
  color: white;
  cursor: pointer;
  padding: 15px;
  border-radius: 4px;
}

#myBtn:hover {
  background-color: #660066;
}
</style>
</head>
<body>

<button onclick="topFunction()" id="myBtn" title="Donate">Donate</button>


<div style="background-color:lightgrey;padding:30px 30px 2500px">Wibble.</div>



<script>
//Get the button
var mybutton = document.getElementById("myBtn");
mybutton.style.display = "block";

// When the user scrolls down 20px from the top of the document, show the button
//window.onscroll = function() {scrollFunction()};

//function scrollFunction() {
//  if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
//    mybutton.style.display = "block";
//  } else {
//    mybutton.style.display = "block";
//  }
//}

// When the user clicks on the button, scroll to the top of the document
function topFunction() {
  window.open("https:  TARGET DONATION SITE");
}

</script>

</body>
</html>


Solution

  • At this time it's possible to embed a Google Apps Script web app into a new Google Sites web page but that's all that can be done.

    In other words, what you are trying to do, can't be done on new Google Sites.