-
-
Save cazepeda-zz/3967172 to your computer and use it in GitHub Desktop.
window.location.href | |
==================== | |
Bookmarklet to append a string to the end of the URL. | |
1. Create bookmark. | |
2. Edit bookmark URL(Chrome) / Location(Firefox) to include this code: javascript:window.location.href=window.location.href+'REPLACETHIS'; | |
3. Now make use of that bookmarklet. | |
Code: javascript:window.location.href=window.location.href+'REPLACETHIS'; |
Are you sure / did you test this? I'm pretty sure it will change to
example.com/hello?foo=1&KEY=VALUE
. That's the documented behavior, too: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/set#examples
oops... you're absolutely right it does work... I missed that you were initializing with the location.search). My apologies!
But it is still half as long :)
How do I make a bookmarklet which adds "about:reader?url=" to the beginning of the URL?
How do I make a bookmarklet which adds "about:reader?url=" to the beginning of the URL?
Honestly, I don't think you can from a bookmarklet in modern Chrome due to the security settings. If you try to it redirects you to an about:block page.
Even from the DevTools console if you try the following it's blocked. I certainly don't want to say that it can't be done by somehow loosening security settings, via some JS glitch, or via an extension, but in terms of a traditional bookmarklet that will work for most people, I don't think it's possible. It isn't allowed in modern Firefox either.
location.href = 'about:reader?url=https://www.google.com'
Are you sure / did you test this? I'm pretty sure it will change to
example.com/hello?foo=1&KEY=VALUE
. That's the documented behavior, too: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/set#examplesWhat it will replace is any existing parameters of KEY. So if you have
example.com/hello?foo=1&KEY=bar
, it will becomeexample.com/hello?foo=1&KEY=VALUE
, whereas the original bookmarklet will yieldexample.com/hello?foo=1&KEY=bar&KEY=VALUE
.My use case was on GitLab issues; when viewing group level kanban boards, there was a url parameter that allowed you to filter to a single project, but no UI element to do this. But if the parameter was present twice, it would only use the first one. So I needed to replace it (while keeping all other parameters), not add an additional param on to the end. (I'm pretty sure this parameter trick no longer works, though).