Skip to content

How to close the current page by button click? #1542

Closed Answered by natankeddem
Anindya088 asked this question in Q&A
Discussion options

You must be logged in to vote

The run_javascript method not only executes the code, it also allows for data to be returned from the page. I am guessing the return hooks don't like that you closed the page before they could do their thing. This seems to keep it from trying to wait on data return:

from nicegui import ui


async def close_page():
    await ui.run_javascript('window.close()', respond=False)
ui.button('Button', on_click=lambda: close_page())

ui.run()

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Anindya088
Comment options

@falkoschindler
Comment options

Answer selected by rodja
Comment options

You must be logged in to vote
1 reply
@python-and-fiction
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants