r/webdev
•
u/ishtiaq156
•
Jun 01 '21
•
1
Resource That feeling when you first discovered `document.designMode`
631
Jun 01 '21
Mindblowing! This is awesome!
Much much much better than choosing one element and trying to edit the text or HTML over developer tools
154
76
u/KingKongOfSilver Jun 02 '21
So all this "design" mode can do is edit texts? I guess my expectations were a bit too high of a mode called "designMode"... Seems quite useless to be honest
13
Jun 02 '21 edited Jun 02 '21
Yeah, it's only editing text, but you can also organize your elements and put them in different locations with simple copy/cut-paste. I believe that makes it more useful.
7
19
12
u/Hairy_Shine_6629 Jun 05 '21
I just gave your post 696969 upvotes with this awesome trick. You're welcome
3
221
Jun 01 '21
Also don't miss out on the contentEditable="true" attribute to target specific element.
19
u/JasperNykanen := Jun 02 '21
<div contentEditable></div>Works just the same, the explicit
="true"is considered an anti-pattern.→ More replies (2)1
77
u/kylegetsspam Jun 02 '21
And don't forget that Chrome is a conflict of interest, a browser made by a marketing firm, and is selling all your data.
63
u/TheSpiffySpaceman Jun 02 '21
We all know; we still have to support it to make the paycheck though.
24
u/Sackadelic Jun 02 '21
I find FF’s dev tools just as good, better in some departments.
→ More replies (2)8
Jun 02 '21
How is that relevant to the comment you're responding to?
10
u/Sackadelic Jun 02 '21
I misunderstood. Thought that the poster was saying basically “we have to use chrome for development”
4
32
u/nikehat Jun 02 '21
What does this have to do with anything from this post?
4
u/Ph0X Jun 03 '21
And how does it have 60+ upvotes? This is literally what downvotes are for, not for things you disagree with, but for offtopic unrelated comments like that.
7
u/i_took_your_username Jun 02 '21
It has nothing to do with the post or the comment he replied to. /u/kylegetsspam only posts comments about things he's complaining about or people he's better than.
→ More replies (7)5
0
Jun 01 '21
[deleted]
111
20
Jun 01 '21
1
u/SquareWheel Jun 02 '21
Your link is broken because you tried escaping an underscore.
Here is the real link.
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content
→ More replies (1)35
u/ClassicPart Jun 01 '21
Can't find anything
Literally the first result for
contenteditableon both Google and Duck Duck Go will give you the link to MDN, which has more information than you will ever want to know about it.I assume you couldn't find anything because you didn't actually bother searching and instead expected everyone to spoon-feed you.
23
u/bgeyts667 Jun 01 '21
20
u/mypetocean Jun 01 '21
As someone who used this feature over the weekend (for use in a CSS teaching tool), a few words of warning about
contentEditable:
The default behavior will insert a DIV or SPAN every time you hit Enter/Return. The only way to change this behavior natively is browser-specific (Chrome has
contentEditable=plaintext-only). The only other way around this, is to use the Shift+Enter hotkey to insert a newline character without HTML formatting.In fact, pretty much everything interesting about this HTML attribute is the browser-specific implementations. That also means... That's right: you should mostly avoid using it. My educational case works because I am using the page for a screenshared demo.
The Tab key maintains its element focus behavior. So if you want Tab to insert a tab character or a soft-tab, you need to listen for Tab keypresses, do
event.preventDefault(), then do an execCommand to insert text at the location of the text cursor caret:document.execCommand("insertText", false, " ")5
u/ManiacsThriftJewels Jun 01 '21
Nah bruh, execCommand is deprecated. You need to getSelection, check it's a caret, convert to a range, make sure the container's a text node, split the text node, insert a new text node containing a tab in the parent element after the preceding text node, and if you're nice you might even normalise the parent element...
But wait, that's marked as experimental and prone to change...
→ More replies (2)2
u/mypetocean Jun 02 '21
Exactly. There is no non-bodged, cross-browser, or standards-compliant way to do this stuff.
This weekend, I so happen to have been privileged to ignore those concerns because only I had to be burdened with them.
18
u/dons90 Jun 01 '21
Wait where did you even look?
contentEditableis very easy to find information on 🤔25
u/MindlessSponge javascript Jun 01 '21
It's much easier to just say you can't find it, then someone will reply with exactly what you want to know - rather than "wasting your time" looking it up and reading all that extraneous detail.
Same logic as posting the wrong answer instead of asking for the right answer, I suppose.
7
u/Noch_ein_Kamel Jun 01 '21
contentEditable let's you eat the content.
edit: also it's called Murphys Law
→ More replies (2)6
1
u/evilgwyn Jun 02 '21
Lol the internet is so dumb it doesn't even have any content editable documentation
0
Jun 01 '21
[deleted]
2
u/dons90 Jun 01 '21
he was probably expecting it to be a console command
Well that may be true, but if a console command doesn't immediately come up, the next step is the search engine no?
0
1
193
u/oompahlumpa Jun 01 '21
They call it design mode but it seems like all you can do is edit text?
184
u/human_brain_whore Jun 01 '21 edited Jun 27 '23
Reddit's API changes and their overall horrible behaviour is why this comment is now edited. -- mass edited with redact.dev
65
u/NotChristina Jun 01 '21
The latter is 100% what I’ll use this for. I had no idea it was a thing. I do a lot of on-the-fly demos for internet stakeholders and many times they just want screenshots. This will definitely be a timesaver.
28
u/su-z-six Jun 01 '21
I'd say about once a week I open up dev tools in a stakeholder meeting to demo a simple HTML edit and create a screenshot.
This will only save me a few seconds, but more importantly I don't have to jump into code while screen sharing. That is always when the top level leadership loses interest.
→ More replies (2)5
8
u/Tokogogoloshe Jun 02 '21
But can you save those changes? I’m just curious.
7
u/TheAnxiousDeveloper Jun 02 '21
I think you simply edit the source code. There is no way that a client side modification (on the aesthetic) is going to do it for you.
1
u/MarmotOnTheRocks Jun 02 '21
Nope, it reverts to the original content as soon as you reload the page. It's just a visual tool on the client side.
0
Jun 02 '21
[deleted]
2
u/etvorolim Jun 22 '21
That's very interesting. I was thinking about that. Just having a save button that calls for a function that saves the inner HTML of an array of editable elements.
Also, ESP32 ftw.
0
6
u/greghuels Jun 01 '21
I'm sure there's also good use in seeing how responsive different content is to window size changes in the event that the content is dynamic. Could also just edit the html for that though
→ More replies (2)2
u/rich97 Jun 02 '21
Question: if you’re using file system mapping and you edit using design mode does that reflect on the file system once you saved?
109
u/xSypRo Jun 01 '21
Same, i don’t really understand the hype. Am i missing something?
13
1
u/KamikazeHamster Jun 02 '21
Do a demo on a website with a client, they ask what it would look like if <x> is worded different or what it would look like if <y> is in a different location. No need to open the dev tools and fiddle with the source code - you can literally highlight the component you want, cut it and paste it somewhere else.
1
Jun 02 '21
Yeah, this isn't useful for any js generated website, but could be nice if you're showing a page to someone who isn't tech savvy and they want something minor changed.
0
Jun 01 '21
[deleted]
18
u/xSypRo Jun 01 '21
I mostly use dev tools to mess around with sizing and colors. But why edit the text content like that?
36
u/DoctorProfessorTaco Jun 01 '21
In my case I’m often building out a frontend before I have data available (and occasionally before I even know exactly what the data will look like or what pieces of data I’ll have), and I’ll want to make sure it looks good and operates properly when displaying several different examples of possible data so I’ll have as few changes as possible when I actually get real data. Now to do that, I could look at the page with one example, edit the code, recompile, and look at the new example, or I could edit the text in the element inspector, but being able to just type it out directly on the page makes it way easier than either of those options and allows me to try many different examples quickly. It’s also nice from a design perspective if I want to try out different descriptions or labels or titles without having to edit the element directly or edit my code.
→ More replies (1)4
u/undercover_geek Jun 02 '21
This is by far the best argument for it's use I've seen in the comments.
14
u/SoBoredAtWork Jun 01 '21
Make quick mocks for A/B testing. Proof of concept screenshots. Fake data without having to go into the source. Etc.
3
u/Cafuzzler Jun 02 '21
Off the top of my head I think one possible practical use could be checking how your design handles custom user names: What happens if the username is 40 characters long, or uses emojis, or uses an arabic or chinese script, or someone tries to use crazy g̴̨͛͠ḻ̵̞̂i̸̞͔̊ṫ̴̘c̸̮͖̔h̶̖̊͜ text. You can test all of that, and test it with dynamic resolution and mobile formatting, on the frontend side of things without refreshing or reloading the page. Of course there are plenty of other ways to test those things too, but it's an option that's unobtrusively there if you need it.
→ More replies (2)3
u/AcousticDan Jun 01 '21
Neat, what's the problem one would solve with this? Tricking old ladies out of their hard earned cash?
7
u/pagelab Jun 01 '21
I use this to grab screenshots of restricted areas that have information I need to change.
→ More replies (2)2
u/npmbad Jun 01 '21
It's only use I found was trying to find good headlines for my landing pages. It really did help in that case.
2
3
1
u/Ph0X Jun 03 '21
To be fair, back when it was added, the web was basically just more or less pure html and websites were all mostly text.
24
u/unkill_009 Jun 01 '21
So if I get this correctly, will the CSS/HTML code change too? and I just need to copy it in my VS Code
23
u/JBlitzen Jun 01 '21
It’ll change, but there’s no standard between browsers or versions regarding what it will change TO, so be careful with it.
Getting the new code out dynamically can also be a challenge since not all dynamic code is aware of user changes.
3
14
u/montrayjak Jun 01 '21
In the dev tools, go to the
Sourcestab ->Filesystem(top left) andAdd folder to workspace. Then your changes will be saved. Code too (ctrl+S after making changes). And any CSS changes you make. You can essentially use your browser as a WYSIWYG/IDE.Changing code on the fly after setting a breakpoint feels pretty magical. I do it a lot for projects.
Note: this gets less reliable if you're using React. VueJS seems to work fine for me though.
3
0
21
u/Strikerzzs Jun 01 '21
That's cool! But is it an experimental feature for Chrome Dev Tools?
36
9
2
u/Ph0X Jun 03 '21
It's really really old, Both Chrome and Firefox have had it since 1.0
It was actually useful back when the web was just pure html.
2
Jun 01 '21
a web developer will just edit the content in inspect element no? maybe this is exciting for non technical people
3
6
u/funknut Jun 01 '21
You ever have to implement a JavaScript based wysiwyg editor for basic text formatting on a content management platform? It's pretty simple, but this is even simpler.
6
Jun 01 '21
that's a pretty contrived example, I think almost everyone uses an external library for WYSIWYG editors. I don't think this mode is supposed to be used for production anyway.
→ More replies (1)1
u/funknut Jun 02 '21
You're referring to what I'm referring to. I am referring to a JavaScript library, as well.
5
u/SleepyHarry Jun 01 '21
Huge generalisation.
In short, no. This is useful for fucking around with copy on a live site. I've used it on several occasions where I want to mess with various thing and right click - inspect element - click a bunch to get the text part - click out - Close devtools is a laborious process once, let alone several times on a site.
I've also used it for more QA related things where the amount of text is variable and I wanna see if I can break it. Again, saves a load of clicks / labour.
1
4
1
u/bullsized Jun 01 '21
How do you insert emoticons?
3
u/ishtiaq156 Jun 01 '21
You mean emojis?
On Mac use:
Control + Command + Space
For Windows:Win + .orWin + ;2
u/nuby_4s Jun 01 '21
my ass has been googling emoji's and copy/pasting on desktop for far too long, just blew my pea sized mind
7
u/BehindTheMath Jun 01 '21 edited Jun 01 '21
Source:
https://twitter.com/sulco/status/1177559150563344384
Edit: For all those downvoting, the post title and GIF came straight from this tweet. Give credit where it's due.
1
u/sulcoff Jun 02 '21
+ in the original video there's music which adds to the entertainment value.
Goddamn thieves :/
4
2
2
2
2
2
u/elbojoloco Jun 01 '21
This is just like setting contentEditable to true on the body element isn't it?
2
u/iWritePythonLikeThis Jun 01 '21
My instructor had this and I never understood why a blinking cursor would appear on wherever on the page he clicked until now
2
u/SleepyHarry Jun 01 '21
Sub protip is to wrap this into a bookmark (create a bookmark then edit the URL to be javascript:<code here>) and stick it on your bookmark bar. Now you don't even need to open devtools and type it out. Literal seconds per month saved.
2
2
u/iamasuitama Jun 02 '21
When would you need this for webdev? I can see needing it for fake twitter screenshots, but webdev?
3
u/Curiousgreed Jun 02 '21
Plenty of reasons, in general I do it to test if the layout breaks with longer texts.
2
4
0
u/whitecrow_dragon Jun 01 '21
I stopped using Chrome after I noticed it was eating 8gb of memory :'(
8
u/ishtiaq156 Jun 01 '21
What’s nice about this is, it’s supported by all major browsers. Check it out here https://caniuse.com/?search=Designmode
1
4
u/4TH4RV- Jun 01 '21
Wtfff how is this not popular. Thank you for showing this to me
33
Jun 01 '21
Because it's not really useful. There are better tools to design a web page, and rarely will you need to change page text/css on the fly
2
1
1
1
1
1
1
u/luzacapios Jun 01 '21
Dannnnngggg! 😎 magic! I see some interesting possibilities. I hope I remember this when an opportunity arises.
1
1
1
1
u/nothankyouthankstho Jun 01 '21
Got excited. Showed partner. Deleted their Tumblr because I played with fire
1
1
1
Jun 01 '21
does it do anything except turn the page into a big series of text fields? can you change the layout or anythign?
1
1
1
1
1
u/TankorSmash Jun 01 '21
If you see the autocomplete grey text, just hit tab, don't type it out if you don't have to.
1
1
1
1
1
1
1
1
u/turbotailz Jun 01 '21
How does this work with reactive libraries? Say I have a reactive title and the user is able to change that title using designMode, will the library react to the change or does this screw things up?
1
1
1
Jun 01 '21
“I was just reading your final edit — um, there seems to be an inordinate number of exclamation points.”
1
1
1
1
1
u/jonesy346 Jun 02 '21
Bruh this is amazing this is literally the highlight of my week so far, thank you for this wonderful tip 😊❤️
1
1
1
1
1
1
1
1
1
1
1
1
1
u/LightReads Jun 02 '21
Looks good. Would you guys know of any other application/site that does similar? Thanks!
1
1
1
1
1
u/HemetValleyMall1982 Jun 02 '21
For us, it is fantastic, but may have a dark side.
After compromising a user's computer, scammers have ways to use the DOM inspector to alter the way a mark's browser displays bank account information. This makes it much easier for the scammer. For more about this, see Kitboga's channel on YouTube.
1
u/therealangryturkey Jun 02 '21
I'm curious how a scammer benefits by showing me I have more or less money in my bank account. Maybe that's not what they do, but it is interesting.
1
u/HemetValleyMall1982 Jun 02 '21
Scammer calls 'customer' and informs them that Amazon or Microsoft has overbilled them $700, and they are eligible for a refund.
Somehow, scammer convinces customer to install a remote PC program. Scammer now has remote access to computer.
Scammer tells customer to log into their bank to see the $700 'refund'.
Customer logs into bank, scammer takes control of mouse and enters developer mode in browser, changes bank balance on-screen and/or inserts new divs into DOM to show 'transactions' on the bank account, with bank.com still in the address bar. Looks legit.
Scammer then requests customer to send the $700 back to them using a bank account transfer.
Customer is now out $700.
1
1
1
u/its_dizzle Jun 02 '21
The only thing this is useful for (IMO) is making sure elements work with varying lengths of copy relatively quickly. Because, as we all know, clients will always add more copy than you expected.
1
u/viayensii Jun 02 '21
I remember doing this to prank my classmates in college. it's a shame that I forgot about this now that I have a job.
1
1
1
1
1
u/SeeYouInForever Aug 20 '21
I thought one would be able to do a lot more with the document.designMode function. Although, still a pretty impressive discovery!
1
1
1
u/ConduciveMammal front-end Sep 02 '22 edited Sep 02 '22
Whilst it’s cool as hell, does it actually have any real use cases?
Edit: I just realised I commented on a 1.5 year old post 😑
1
u/Ampix0 Jun 02 '21 edited Jun 02 '21
Credit the twitter account this was stolen from. @sulco
Even the title is from the tweet
0
0
u/gbjcantab Jun 01 '21
Lol that everyone’s amazed... I remember sitting with friends in middle-school home room in, what, the mid-2000s? And messing around with design mode.
0
u/crypt0isthefuture Jun 01 '21
/u/nano_tipper 5USD This is fucking awesome! You literally changed my life!
285
u/shmorky Jun 01 '21
Why 'on' tho?
Why not just true?