dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.52k stars 10.04k forks source link

[Blazor] Intercept navigation from inside iframe #47645

Open rhodon-jargon opened 1 year ago

rhodon-jargon commented 1 year ago

Is there an existing issue for this?

Describe the bug

When a link (<a> tag) is clicked within an iframe but its target is the parent frame (the one running blazor), it is treated as external navigation (e.g. blazor has to reload) even if its href is within the base tag. I have already tried multiple ways to fix this, like setting the target to _top or _parent, or adding a <base> tag to the iframe (with the same href as the parent's <base> tag, and/or with a target of _top or _parent instead of the <a> tag). I understand this might not be possible to prevent when the iframe is a different origin, but the bug also occurs when setting the contents of the iframe using the srcdoc attribute. I have only tested this in Blazor Webassembly, though I suspect Blazor Server works the same way.

Expected Behavior

When an internal link is clicked within the iframe, the internal router of blazor handles the redirection without reloading if possible.

Steps To Reproduce

Create an iframe with the srcdoc set to <a href="/some-internal-link">Click</a>. Clicking the link reloads the page. I also made a sample project based on the Webassembly template: FrameNavigation. The problem can be seen on the Counter page.

Exceptions (if any)

No response

.NET Version

7.0.202

Anything else?

Context: I am using an iframe to isolate (trusted) user content from the main layout, so that the user can supply custom CSS and HTML without affecting the main page. However, the user content should be able to link to other user content/pages.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 11 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.