Is there a way to click button and open a new link in a new tab?

Similar to this, but make it a button.

'Click <a href="https://panel.holoviz.org/reference/index.html" target="_blank"'>here</a> for docs!'

image

1 Like

If you want it in the same window use

import panel as pn

code = """
window.location.href="https://panel.holoviz.org"
"""

button = pn.widgets.Button(name="Open Link", button_type="success")
button.js_on_click(code=code)
pn.Column(
    button
).servable()
2 Likes

You can also try the window.open method. It will give you more control. See https://www.w3schools.com/jsref/met_win_open.asp

1 Like

Cool!

import panel as pn

code = """
window.open("https://panel.holoviz.org")
"""
button = pn.widgets.Button(name="Open Link", button_type="success")
button.js_on_click(code=code)
button

Is what I need

3 Likes