-
-
Notifications
You must be signed in to change notification settings - Fork 6
Description
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:
-
Hash the PDF URL and use the has as a
@keyon the actualiframeelement. When the PDF URL changes, that would force the PDF to reload. I could then bind theSrcproperty with a cache-busted URL, something likehttps://mysite.com/somecontent?nocache=20251218103005and each time I update thenocacheparam, the iframe would rebuild. -
Better still, if there was an API into the
BlazorFrameto 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!