Betting NodeBB and Discourse ain't gonna have fun with this
-
@TwelveBaud said in Betting NodeBB and Discourse ain't gonna have fun with this:
After the document has been loaded, calling document.write implicitly calls document.open, which clears the entire contents of the DOM.
This explains the number of websites I encounter that seem to partially load and then turn into a useless white screen while spamming errors to the JS console.
-
@TwelveBaud said in Betting NodeBB and Discourse ain't gonna have fun with this:
The real area of difficulty is that both Gecko and Blink speculatively parse HTML even while scripts are still running, so unbalanced writes are evil.
- TODO: document.write inside other formatting elements.
Last updated by: chrisdavidmills, Apr 18, 2017, 9:55:20 AM
-
Well I should probably update that old page I wrote that used an hard-coded array for its data and document.write() to format it because it was much smaller than the formatted form... And for that, I'll have to learn how to manipulate the DOM in the first place (well, I could probably do so without too much difficulty in jQuery, but that means my old page will now depend on it...)
-
@Medinoc The easy way is just to find some unwitting element and jam a bunch of HTML into its
.innerHTML
property.The effort way is more like
var el = document.createElement('span'); // it's a <span> element el.id = 'span_id'; // can set the element's ID property el.classList.add('class1', 'class2', 'class3'); // can add class names (old browsers might only accept 1 class name at a time though) el.setAttribute('data-custom', 'property'); // can set other attributes like this el.style.fontWeight = 'bold'; // can set CSS style attributes like this el.appendChild(document.createTextNode('span content')); // can add child nodes (in this case, a text node) document.body.appendChild(el); // put it somewhere in the DOM
Note that you've created just a single element (with a text node inside). You could, of course, put other elements inside; you have to create each of them and use
appendChild
to put it in the proper place. Waiting until the tree is complete before adding its root element to the document seems logical to me, but I'm not sure if it really matters.The result of this is the same as what you'd get by writing
document.write('<span id="span_id" class="class1 class2 class3" data-custom="property" style="font-weight: bold;">span content</span>');
Alternately, the lazy way is to write
document.body.innerHTML += '<span id="span_id" class="class1 class2 class3" data-custom="property" style="font-weight: bold;">span content</span>';
-
@brie In both cases, you'd be doing this from the body's onload handler, rather than as soon as the javascript loads.
-
@PleegWat Yeah, good point. Either in the
load
event handler, or some other event handler.To really reproduce the while-the-page-is-loading
document.write
, unless you're adding things to the very end of the document, you'd need to put a root element (or a placeholder element) into the page's HTML at that point. Then in theload
event you'd use that element as your reference, either using it as a root element and appending child nodes to it, or usingreplaceWith
to swap your new element(s) into its place.
-
@acrow said in Betting NodeBB and Discourse ain't gonna have fun with this:
Please enable Javascript to view this page.
Haven't seen one of those in ages.
Pages that go completely white? Sure. But pages considering disabled JS a possibility? Nope.
-
@Zecc I've seen a few pages that work or mostly work with "enable javascript for full functionality" at the top
-
@Medinoc said in Betting NodeBB and Discourse ain't gonna have fun with this:
Well I should probably update that old page I wrote that used an hard-coded array for its data and document.write() to format it because it was much smaller than the formatted form... And for that, I'll have to learn how to manipulate the DOM in the first place (well, I could probably do so without too much difficulty in jQuery, but that means my old page will now depend on it...)
If it's a lot of repetitive formatting, it should compress very well with gzip. You might be solving a problem that isn't there.
-
@Zecc Most newspapers used to do this (in Finland), mostly via <noscipt> tag. Less now that fewer frameworks take into account the possibility, I guess.
One of the more recent offenders is one of the banks that I use: op.fi
Edit:
added country specifier to claim
-
When are they going to kill javascript hooking of right click?
-
@PleegWat Google Docs uses it. So never
-
@pie_flavor It should really be a per-site permission, though, like notifications or location.
-
@anotherusername why? It's about interactivity. Notifications is about being able to nag you when you don't have the website open, location is about your personal security. A site overriding right click is constrained to only that site, and if you don't like it why not just find another site?
-
@pie_flavor said in Betting NodeBB and Discourse ain't gonna have fun with this:
Notifications is about being able to nag you when you don't have the website open
No, the desktop notifications API only works when you have the website open. You're thinking of something different.
A site overriding right click is constrained to only that site, and if you don't like it why not just find another site?
For the same reason that I'm still using an adblocker even though "a site displaying ads is constrained to only that site, and if you don't like it why not just find another site".
-
@anotherusername said in Betting NodeBB and Discourse ain't gonna have fun with this:
No, the desktop notifications API only works when you have the website open. You're thinking of something different.
WOMM
For the same reason that I'm still using an adblocker even though "a site displaying ads is constrained to only that site, and if you don't like it why not just find another site".
Ads are harmful for several reasons. If you were just blocking static image ads, I'd be right.
-
@pie_flavor Regardless of whether push notifications work when the site isn't open, it has to request your permission to display desktop notifications even while it is open.
Anyway, sites blocking right click can disrupt the user experience and interfere with the way the user should be able to interact with their browser. Certain websites make good use of it -- Google Maps, for example, or Docs. But other sites do it just to block the default right click menu and I would prefer to be able to block that.
NoScript to the rescue, I guess.
-
@anotherusername No, it just affects their ability to interact with that single website. Everything you've described so far affects your interaction outside of the website. The context menu is completely limited to that site.
-
@pie_flavor it's fine, really, because I'll just go on using NoScript.
-
If it were a per-site permission, even if on by default, both you and @anotherusername could have your ways.
FWIW I'm a bit annoyed when I can't open the context menu to inspect an element or copy the URL to an image, or something.
-
@TimeBandit said in Betting NodeBB and Discourse ain't gonna have fun with this:
The next one will be to GitHub.
Threads will be repos
To comment you'll have to git pull, add your comment then git push
Your commit comment will have to be useless, of course.
Conflicts? Just git push --force
Threads derailment will be forked.If you fuckers want to get rid of me, this is all you would have to do.
Oh yes, I realize that some snowflakes will all be on board now and start pushing for it. Remember that I am one of those guys that just wants to watch the world burn. :)
-
@Polygeekery said in Betting NodeBB and Discourse ain't gonna have fun with this:
@TimeBandit said in Betting NodeBB and Discourse ain't gonna have fun with this:
The next one will be to GitHub.
Threads will be repos
To comment you'll have to git pull, add your comment then git push
Your commit comment will have to be useless, of course.
Conflicts? Just git push --force
Threads derailment will be forked.If you fuckers want to get rid of me, this is all you would have to do.
Liar.
-
@Gąska if you think I would deal with Git in order for me to have semantic arguments with you, you are sorely mistaken.
I mean, maybe before I started ADHD meds. Well, probably before the meds. But not now. The field in which my fucks are grown has had the earth salted.
-
@Polygeekery I'll try not to use this information in future
discussionsname callings. Congrats on making your life better, stay strong, don't put them away!
-
@anotherusername said in Betting NodeBB and Discourse ain't gonna have fun with this:
Anyway, sites blocking right click can disrupt the user experience and interfere with the way the user should be able to interact with their browser. Certain websites make good use of it -- Google Maps, for example, or Docs. But other sites do it just to block the default right click menu and I would prefer to be able to block that.
NoScript to the rescue, I guess.
Or just press the context menu key (of Shift-F10, if your keyboard doesn't include it).
-
@Zerosquare said in Betting NodeBB and Discourse ain't gonna have fun with this:
Shift-F10, if your keyboard doesn't include it
TIL.
Mine doesn't, so thanks.