Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use add_body_html in a dialog ? #4157

Open
kongds1999 opened this issue Dec 31, 2024 · 0 comments
Open

how to use add_body_html in a dialog ? #4157

kongds1999 opened this issue Dec 31, 2024 · 0 comments

Comments

@kongds1999
Copy link

Description

Initially, I tried to render an HTML page within an open dialog. I used ui.html, but I discovered that my HTML code contained JavaScript code, so I used ui.add_body_html. The code didn't report any errors, but I didn't get the result I wanted; my HTML didn't render.
I kept ui.add_body_html, but removed the js code from the parameters. I found that the code was executed, but my html result was displayed on the main interface instead of in the dialog.
As a beginner, I don't know if this is a feature of nicegui, but I really want to know how to achieve my original goal: rendering HTML content with JavaScript code into my dialog window.
Looking forward to your reply.

from nicegui import ui

def open_dialog():
    with ui.dialog() as dialog, ui.card().classes('w-full h-full'):
        ui.label('This is a dilog')
        ui.add_body_html('<p style="color: red;">This is custome HTML content</p><script type="text/javascript">console.log("hello")</script>', shared=True)
        ui.button('close', on_click=dialog.close)
    dialog.open()

ui.button('open dialog', on_click=open_dialog)

ui.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant