Skip to content

Buttons for HTML/JS control page #2095

Answered by micahnyc
hedbergj asked this question in Q&A
Discussion options

You must be logged in to vote

What you have is the right idea. Here is a snippet of javascript that creates a button to trigger an action:

function createOpenSpaceButton(buttonTitle, actionIdentifier) {
  // create a new button with title
  let newButton = document.createElement("button");
  newButton.innerHTML = buttonTitle;
  // assign click function to button
  newButton.onclick = function () {
    openspace.action.triggerAction(actionIdentifier);
  };
  //append the new button to the button container
  var buttons = document.getElementById("buttons");
  buttons.appendChild(newButton);
}
// create buttons
createOpenSpaceButton("Hello World", "profile.focus.earth");
createOpenSpaceButton("Toggle Zoom Friction", "os_…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by alexanderbock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants