Skip to content

Feature Request: easy way to force reload the iFrame content #10

@Webreaper

Description

@Webreaper

I have a PDF preview rendered in the iFrame, which regularly needs to be refreshed. It would be really cool if there was a simple way to do this.

For now, I'm doing what this SO article suggests: https://stackoverflow.com/questions/72884980/i-have-an-iframe-in-my-blazor-server-app-razor-page-in-that-an-external-url-is-d

I'm applying an @key to the BlazorFrame component, with the key set to a timestamp string and whenever the timestamp changes, I call StateHasChanged and Blazor will re-render the entire component.

But that's a bit heavyweight. It would be nice if there was a slicker way to do it. I see there being two potential options:

  1. Hash the PDF URL and use the has as a @key on the actual iframe element. When the PDF URL changes, that would force the PDF to reload. I could then bind the Src property with a cache-busted URL, something like https://mysite.com/somecontent?nocache=20251218103005 and each time I update the nocache param, the iframe would rebuild.

  2. Better still, if there was an API into the BlazorFrame to reload so it executed some Javascript to force-reload the PDF, that would be cool, and would require less DOM destruction and recreation. That's probably getting a little over-complex though.

Let me know what you think!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions