How to make a link open in the current tab

a bit late but you can do something like:

in Native Libraries:

function open_url_same_tab(url) {
  window.open(url, "_self");
}

link click event

self.link.tag = some_url # set this in the design view

def link_click(self, **event_args):
  js.call_js('open_url_same_tab', self.link.tag)

proof of concept
https://anvil.works/build#clone:FPDIXYWNGETIDKY4=RTZT5HHDHUEY6QJN2K5HGRAP



EDIT: since this post anvil has improved its js integration:

from anvil.js import window

def link_click(self, **event_args):
  window.location = url
  # or window.open(url, "_self")

If you want to open it in a new tab you could use window.open(url) instead

7 Likes