[BUG] openExternal stuck in a loop

I try to open a website from a model dialog, which works fine. However, whenever I get back to Photoshop, the website gets opened up again and the browser gets the focus back. I can only stop this by reloading the plugin. Any ideas what’s happening here?

Here’s the code ( tried the onlick version as well - without success) …

document.getElementById("button_website").addEventListener("click", async evt => {
  await shell.openExternal("https://www.google.com");
});

Is it necessary to have an event listener? I used a normal <a href="" /> in my plugin dialog and it works perfectly fine

1 Like

Maybe with an sp-button it is. I also tried the inline version with “onlick” and it doesn’t work either. Did you try it from a modal dialog?

You can use
<sp-link href="https://www.google.com">Click Me</sp-link>

2 Likes

I tried in 3 types of dialogs:

  • uxpShowModal()
  • showModal()
  • show()

Didn’t notice any difference, apart from show() still letting interact with the app behind the dialog.


Now I’m thinking… What do you mean by this?

whenever I get back to Photoshop

How do you get back? Another button? Could it be by some accident you have two buttons with same ID and when you click this other “Close dialog” button it also triggers the link?

Check this answer by Kerri

inline event handlers are not supported

sp-link works. I will have to design the button for it though. The question is, why is sp-button acting so weird. I use the same technigue directly from the panel and there are no issues there.

Cheers.

“Getting back means” switching the focus back to Photoshop. In Windows by ALT-TAB or just by clicking on the tab at the bottom of the screen. It’s doesn’t matter which I use.

I use the inline version in a few places and it works. So that’s not the reason. It also works here - although not properly (as well as the external function handler).

If you don’t want the link to show up as underlined, you simply add quiet :

<sp-link quiet href="https://www.google.com">Click Me</sp-link>

Thanks. I’ll keep that in mind. But I would prefer the sp-button.

In that case, here’s a button-link :slight_smile:

<sp-action-button onClick='require("uxp").shell.openExternal("https://www.google.com")'>
  Click me
</sp-action-button>

// or 
<sp-button onClick='require("uxp").shell.openExternal("https://www.google.com")'>
  Click me
</sp-button>
1 Like

Yeah. That’s the one that doesn’t work.

It works, I use it all the time…

Me too. But in my modal dialog, it’s causing the loop.

Can’t reproduce that, sorry. Maybe something odd in the dialog?

There’s not much in there …

<dialog id="dialog_about">
        <sp-button id="button_click" quiet variant="secondary">Click</sp-button>
  </dialog>

Just giving ideas at this point :slight_smile:
Do you maybe have multiple dialogs with same button ID? Or maybe somewhere outside of the dialog? To me it sounds like there’s something with IDs and/or selectors

1 Like

No. It’s the only one with that ID. And I just created a button in another dialog and the issue happens there as well. So it’s not specific to this individual dialog.

And as mentioned before - in the panel itself, the same button works fine.

How do you show the dialog?