2

I'm struggling in linking an HTML link <a> with a JavaScript function using Google Apps Script. I tried the following, but it left me with this error message:

"Unsafe JavaScript attempt to initiate navigation for frame with origin 'https://script.google.com' from frame with URL 'different url'. The frame attempting navigation must be same-origin with the target if navigating to a javascript: url"

My code:

var link = document.createElement("a");
link.setAttribute("href", "javascript:test()");
link.textContent = "Click";

//----------------------------------------------
function test() {
    console.log("Test");
}

The code is placed in an HTML file between:

<script>
</script>

Everything is coded in the IDE of Google Apps Script.

2
  • 2
    The error message should be added as text, not as image. Commented Mar 5, 2020 at 16:00
  • 1
    Added the error message as plain text, so that I could get found by search engines. Commented Mar 6, 2020 at 7:34

3 Answers 3

2

Use the onclick javascript function instead:

<a onclick="myFunction()">Click me</a>

https://www.w3schools.com/jsref/event_onclick.asp

Sign up to request clarification or add additional context in comments.

1 Comment

@maxgotstuck Your second comment should be in a separate question
2

don't use href. Use the onclick event for JavaScript functions.

Comments

1

href is an attribute used to define the target of the link. The right attribute to use for click-triggered events is onclick.

See the W3C documentation for href and onclick

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.