dummydumdum
dummydumdum

Reputation: 11

Redirecting to another Google Script webapp after button click

I'm trying to redirect a google app script web app onto another app script after button click. I have tried the following:

<button onclick="myFunction()">Replace document</button>
<script>
function myFunction() {
  location.replace("https://www.w3schools.com")
}
</script>

The error is that google script refused to connect. When checking inspect element, it says "X-Frame Options" to 'same-origin'.

Is there a work around on this?

I could use tags but how do I display it after an alert?

Upvotes: 0

Views: 1901

Answers (2)

TheMaster
TheMaster

Reputation: 50798

Issue:

  • Trying to load https://www.w3schools.com in a iframe: Note that your script is served in a sandboxed iframe of different origin by Google. The location here refers to the sandboxed iframe @ https://*-script.googleusercontent.com hosted inside https://script.google.com. When you replace the location, you're replacing the inner sandboxed iframe with w3schools website. Now, w3schools doesn't want to be inside script.google.com or any other website. So, it set it's X-Frame Options to same-origin. Some websites are ok with this. They can be embedded. w3schools isn't one of them.
 =============  
 |GASWebApp  |<---script.google.com[Top Frame]
 |           |  
 |=========  |  
 ||SandBox|  |  
 ||User   |<-|---- Where your html code is
 ||Frame  |  |    (*.googleusercontent.com) 
 |=========  |     [Sandboxed iFrame]
 |           |  
 =============  

Solution:

  • Load the web page in the top frame

Snippet:

window.top.location.replace("https://www.w3schools.com")

References:

Upvotes: 1

Cat
Cat

Reputation: 4246

Would something like this handle your use case?

var trigger = document.getElementById("trigger");
var link = document.getElementById("link");

trigger.addEventListener("click", showMessageAndThenShowLink);

function showMessageAndThenShowLink(){
  alert("You are about to see the link");
  link.style.display = "inline";
}
#link{ display: none; }
<button id="trigger">Show Message</button>
<br />
<a id="link" href="https://www.w3schools.com">www.w3schools.com</a>

Note: In an SO snippet, clicking the link gives a "refused connection" error, but it worked fine from my desktop.

Upvotes: 0

Related Questions