htmx icon indicating copy to clipboard operation
htmx copied to clipboard

make the base of URL constructor configurable?

Open hesxenon opened this issue 10 months ago • 3 comments

I have a rather niche use case (and will probably deploy a fork for now) where I'm trying to use HTMX out of an iframe with [href=about:srcdoc]. So when HTMX tries to construct any URL at all it's expanded to new URL("the path", "about:srcdoc") which obviously isn't a valid url.

Would it be possible to add a config option to specify the base parameter?

Like

urlBase?: undefined | string | "root"

where "root" would have the special meaning of using the root windows url.

hesxenon avatar Feb 25 '25 13:02 hesxenon

Hey, as it's a niche usecase, I would recommend either:

  • Adding a htmx:configRequest event listener in your JS to modify the request's URL through event.detail.path (just realized that this event's documentation doesn't mention path though... But it's here!)
  • Creating a custom extension to handle that (that would use the same mechanism as described in my first point, this would simply allow you to configure it per-element with for example the said URL prefix in an attribute value)

Hope this helps!

Telroshan avatar Feb 26 '25 07:02 Telroshan

Hey, yes it helped, thank you :) not sure if I should close this though, I can still see a use case for this 🤔

On Wed, Feb 26, 2025, 08:43 Vincent @.***> wrote:

Hey, as it's a niche usecase, I would recommend either:

Hope this helps!

— Reply to this email directly, view it on GitHub https://github.com/bigskysoftware/htmx/issues/3212#issuecomment-2684179642, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOHZTQUU2EBHZEHLGXTDZD2RVWBLAVCNFSM6AAAAABX2TPHCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBUGE3TSNRUGI . You are receiving this because you authored the thread.Message ID: @.***> [image: Telroshan]Telroshan left a comment (bigskysoftware/htmx#3212) https://github.com/bigskysoftware/htmx/issues/3212#issuecomment-2684179642

Hey, as it's a niche usecase, I would recommend either:

Hope this helps!

— Reply to this email directly, view it on GitHub https://github.com/bigskysoftware/htmx/issues/3212#issuecomment-2684179642, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACOHZTQUU2EBHZEHLGXTDZD2RVWBLAVCNFSM6AAAAABX2TPHCKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBUGE3TSNRUGI . You are receiving this because you authored the thread.Message ID: @.***>

hesxenon avatar Feb 27 '25 17:02 hesxenon

the latest version 2.0.5 now has this:

    const url = new URL(path, location.protocol !== 'about:' ? location.href : window.origin)

This hopefully handles about:srcdoc use cases

MichaelWest22 avatar Jun 22 '25 23:06 MichaelWest22