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

Using htmz without updating browser history #2

Closed
lpil opened this issue Feb 19, 2024 · 8 comments
Closed

Using htmz without updating browser history #2

lpil opened this issue Feb 19, 2024 · 8 comments

Comments

@lpil
Copy link

lpil commented Feb 19, 2024

Hello!

Thanks for this library! It's very cool.

Do you have a recommendation or an extension for not adding to the browser history when clicking on htmz links? I'd like my back button to (for example) go to what my user sees as the previous page rather than resetting a form to a previous state.

Thanks,
Louis

@Kalabasa
Copy link
Owner

Kalabasa commented Feb 19, 2024

I discovered this by accident.

In the cf_clean_target_tabs example. There are named iframes for each destination, following the "Clean target values" approach. These iframes are inside the target elements, meaning they get replaced everytime the target updates.

Apparently, removing an iframe deletes its browser history from your global browser history. So the cf_clean_target_tabs example doesn't record history!

As for a non-accidental solution, unfortunately I don't have any idea other than asking whatwg for a native HTML way. Edit: The official ask: whatwg/html#6501

@drmercer
Copy link

Maybe the iframe could destroy and recreate itself after every action? Interestingly, that would solve #13 as well I think

@Malix-off
Copy link
Contributor

@drmercer indeed, but I don't think it's a good idea performance-wise.
No idea if it would break some part of the previous history too.

@Kalabasa
Copy link
Owner

Explicitly destroying & recreating the iframe sounds feasible

Maybe even simply removing & reinserting the node instead of recreating from scratch as suggested here https://stackoverflow.com/a/25365973/3144156

I think I might need a separate page to collect these extensions.

@niutech
Copy link

niutech commented Feb 22, 2024

Why not just use <object> tags?

@Kalabasa
Copy link
Owner

I just tried <object>, and <embed>. Unfortunately we can't target those elements with the target attribute.

@Kalabasa
Copy link
Owner

simply removing & reinserting the node

I've added this solution in the brand new Extensions page!

@lpil
Copy link
Author

lpil commented Feb 24, 2024

Brilliant! Thank you so much @Kalabasa 💜

The page looks great too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants