Opening html content in new tab from bookmarklet (Firefox)
Opening html content in new tab from bookmarklet (Firefox)
I had a few bookmarklets that used a technique like:
javascript:(function()open('data:text/html,'+encodeURIComponent('<!DOCTYPE html><html><head><title>Title</title></head><body><h1>Title</h1>Content</body></html>')))()
This basically opens some text/html content in a new tab/window using a data url.
This technique apparently does not work anymore in Firefox 61.0.1 (haven't tested other versions). Is this a bug or by design?
A particular implementation using a javascript url doesn't appear to work either.
If this is by design, then is there any simple alternative other than opening a new tab and then writing the content afterwards?
Note: I believe this restriction does not apply to plain text content (possibly others).
1 Answer
1
Partial answer:
javascript:(function()open('javascript:"'+encodeURIComponent('<!DOCTYPE html><html><head><title>Title</title></head><body><h1>Title</h1>Content</body></html>')+'"'))()
The above is a workaround. encodeURIComponent is useful if either double quotes or single quotes need to be escaped (but not both at the same time)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.