Can html fire a script block?

Product: PowerShell Universal
Version: 1.4.6

Is there any way to trigger a powershell script from HTML?

New-UDHtml -Markup @'

<ul id="myList">
  <li id="item1">Item 1</li>
  <li id="item2">Item 2</li>
</ul>

<button onclick="triggerLiClick()">Trigger Item 1 Click</button>

<script>
function triggerLiClick() {
  const item1 = document.getElementById('item1');
  if (item1) {
    item1.click(); // Programmatically trigger the click event
  }
}

// Add an event listener to the li element to demonstrate the effect
document.getElementById('item1').addEventListener('click', function() {
  alert('Item 1 was clicked!');
});
</script>

'@

I’m curious on the use case - why not just use the PSU components for buttons and select boxes?

trying to create a tree view that the nodes can be edited and added to by clicking something, the Mui stuff does not allow it that i can figure out, so i dropped down to HTML, but then i cannot trigger an event, i have given up on this project for now till the MUI controls get expanded, maybe.

Fair enough

An idea but have you checked to see if there’s anything out there which already does what you need: react tree - npm search ?

Though I’ve not done it myself, if there is you could wrap it into a custom PSU component, I think there’s a guide for it in the docs.

1 Like