Opening a webpage from a button

What I’m trying to do: I am trying to open a website (external to my app) on a new tab in whichever browser is being used.

What I’ve tried and what’s not working: I get this message when the new tab opens:

" We could not find an app that matched your request.

You may have copied the URL for this app incorrectly, or this app may have been deleted or withdrawn. You may also have been logged out, in which case refreshing this page might help."

Code Sample:

# code snippet
webbrowser.open_new_tab(self.website.tag)

where website is the name of the button. I have imported webbrowser.

What is webbrowser. Can you share more of your code?

The documentation for webbrowser is here: webbrowser — Convenient Web-browser controller — Python 3.9.2 documentation

The line of code in my button click that I posted is all I am using besides the import.

Is there a better way to open a webpage in a new tab in the default and/or current browser through a button click?

Have you tried using a native Link component?

The issue is that the rest of my design relies on button design, look, and feel, except for this one component. So I don’t want to change it. I would prefer to trigger the webpage open on button click.

I did test embedding a button within a link, but got the same " We could not find an app that matched your request" message as I posted above.

Does this solution work for you?

I get the same " We could not find an app that matched your request" message using that methodology :frowning:

If you publish the app first it seems to work (at least on my end).

I can’t seem to get that to work. Could you try? Here is the link.

The button in question is at the top over the individual name (hover over “Ryan”)

I just tried it on a sample app with a regular Link too as I originally mentioned. Seems to work. Here is the clone:

https://anvil.works/build#clone:XKL33VPY6ZM4RGHP=J3OX4Y3DM643PJVF55Q4CGD7

Here’s the published running app.

1 Like

I must be missing something, somewhere

There doesn’t appear to be code in your click event.

And I got a message about additional libraries not being available on the free plan. Could that be the problem?

The url happens to be set in the properties pane directly. That was what I did just for testing but it can certainly be set in code. Have a look on the right when the link is selected. Your issue is not related to being on a free plan.

Could I ask for you to please take a look? Here is the clone.

https://anvil.works/build#clone:B2ON2LNZIMK6BJYJ=5HXEZHHU556IYMHLFOPEN7MD

I still get that strange message. What I need is to have the button appear when moving mouse into a specific area (that’s what the blank image image_3 is for), and then when the button is clicked open a new tab and go to a specific website.

Hmm, yeah, I tried. I can’t remember what the issue is. I’m sure it’s been covered before on the forum I just can’t remember what the solution/issue was. I’ll look later if I have a second.

Thank you, I would appreciate being able to solve this. Seems like quite a silly problem but it is derailing my entire development right now.

Hi @blumenowster,

@alcampopiano’s solution of a button in a link and having no button click event worked for me once I changed the URL to include “https://”.

Before, it looked like the link was trying to take you to your app’s URL + the URL you entered. Let me know if this fixes your issue!

2 Likes

Brooke, you are amazing. That seems to have solved my issue.

I want you to know you’re an incredible human being.

1 Like

Maybe I should start a fan club :wink:
I’m glad it worked! Good luck with the rest of your project!