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

URL API #74

Closed
Jamesernator opened this issue Dec 9, 2019 · 5 comments
Closed

URL API #74

Jamesernator opened this issue Dec 9, 2019 · 5 comments

Comments

@Jamesernator
Copy link

While these text fragments will often be created by user agents it would be nice to be able to construct these easily in JS so that custom sharing options can be created.

For example Medium does this with selected text:
Screen Shot 2019-12-09 at 6 14 44 pm

It would be nice to be able to do similar with fragment directives using the URL API.

e.g. Example API surface:

const url = new URL(location.href);
url.fragmentDirectives.add('text', window.getSelection().toString());

showShareUrl(url);
@Jamesernator
Copy link
Author

Jamesernator commented Dec 13, 2019

Additional consideration, given fragment directives always come after the hash should the following delete the fragment directives or should they be preserved?:

const url = new URL('https://example.com/#:~:text=hello');
url.hash = '';

@othermaciej
Copy link

I agree this would be useful to add. I think modifying hash, even setting it to empty, should not alter the fragmentDirective. This should likely match the interface added to Location as much as possible.

@bokand
Copy link
Collaborator

bokand commented Dec 19, 2019

Seconded - I think something like add() would be useful so JS apps can easily construct these.

On how url.hash should work I'm less certain about. We'd thought about this to some extent - some of my ideas are in whatwg/url#445 (comment) (back when we were still using ## as the delimiter). There's plenty of cases to consider but I think I covered a bunch there.

What we landed on currently is a minimal change. The HTML Document loading steps will strip the fragment directive from the loaded URL. Otherwise URLs and locations behave exactly as today (e.g. adding a fragment directive to window.location will fire hashchange).

That said, I don't have any strongly held opinions here so I'm open to make changes to URL objects and window.location if we can agree that's a good idea.

@bokand bokand closed this as completed Nov 26, 2020
@bokand bokand reopened this Nov 26, 2020
@zamicol
Copy link

zamicol commented Aug 15, 2022

fragment directives or should they be preserved?:

const url = new URL('https://example.com/#:~:text=hello');
url.hash = '';

Be removed.

A fragment directive is a subset to fragment.

For the other behavior to be reasonable, fragment directive needs to be independent of fragment (and probably a new name to denote this new addition to the URL standard). # is irrelevant for that case as well. If fragment directive is a part of the fragment component, it should following existing rules for fragment. If it needs new rules, it needs to be a new URL component.

@bokand
Copy link
Collaborator

bokand commented Dec 13, 2023

Closing out old issues

Issues around how and when the URL is affected by the fragment directive are now well defined by #225. See https://wicg.github.io/scroll-to-text-fragment/#extracting-the-fragment-directive and the examples in that section for an overview.

Re: having APIs to make it easier to work with (e.g. on URL), that still seems worth having but I think is out of scope for this repo and can be followed up in the HTML standards repo once this is upstream.

@bokand bokand closed this as completed Dec 13, 2023
@bokand bokand closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants