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

Fix navigation when the page contains an iframe with an empty name #767

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/observers/form_submit_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function submissionDoesNotDismissDialog(form: HTMLFormElement, submitter?: HTMLE
function submissionDoesNotTargetIFrame(form: HTMLFormElement, submitter?: HTMLElement): boolean {
const target = submitter?.getAttribute("formtarget") || form.target

if (target === "") {
return true
}

for (const element of document.getElementsByName(target)) {
if (element instanceof HTMLIFrameElement) return false
}
Expand Down
4 changes: 4 additions & 0 deletions src/observers/link_click_observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export class LinkClickObserver {
}

function doesNotTargetIFrame(anchor: HTMLAnchorElement): boolean {
if (anchor.target === "") {
return true
}

for (const element of document.getElementsByName(anchor.target)) {
if (element instanceof HTMLIFrameElement) return false
}
Expand Down
1 change: 1 addition & 0 deletions src/tests/fixtures/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,6 @@ <h2>Frame: Form</h2>
<button id="submit-external-target-ignored">POST to https://httpbin.org/post targeting #hello</button>
</form>
<iframe name="iframe"></iframe>
<iframe name></iframe>
</body>
</html>
1 change: 1 addition & 0 deletions src/tests/fixtures/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ <h1>Navigation</h1>
<turbo-frame id="hello" disabled></turbo-frame>

<iframe name="iframe"></iframe>
<iframe name></iframe>
</body>
</html>