Trying to send my user to a different site - revisited

Added a DEMO clone app to help this conversation. By my read of the documentation and prior responses to this simple action… starting this app should just reroute the use to our website. And, you can see that the link ‘click’ event is executed, however, only by clicking on the link will actually navigate to the url. To repeat/clarify, I want to redirect a user to an outside url, in code.

Still trying to get this to work, I investigated the http module, but I don’t think I should need that. As I continue to test getting a link click event to fire, it is firing… so I’m really puzzled as to why things are not working.

I thought I had solved this, but apparently not. As soon as my app has authenticated a user, I want to send them to another url/website. Consider this code, I have a link on my form named testlink. This is raising the click event in that I do see the debugging text in my output panel, however, the raise_event is not navigating to google.com. When I explicitly click on the link though, it does.

class homepage(homepageTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)

    anvil.users.logout()
    while not anvil.users.login_with_form():
      pass

    self.testlink.url="https://google.com"
    self.testlink.raise_event('click')

  def testlink_click(self, **event_args):
    print('this is the testlink click event')
    print(event_args)

https://anvil.works/build#clone:GVN5AYMPNTUAXYCF=IHPE55EDVKKMBHRPFRSJ5DDG

Hmm, yes this does seem tricky. Probably for good reasons though. From what I can see in this post,

it seems that you actually have to get folks to click on the link or use JS.

I’m not 100% sure though.

Hi @dconnell,

@alcampopiano is correct - you’ll need to get your users to click a link, or drop down to JS for this.

Here’s a simple app that calls a JS function to navigate to the Anvil website after login:

https://anvil.works/build#clone:UYB57GSSGGGWOXSM=3QVOWWI7EJUGQYS4OTTI6H3G

1 Like