Issue #84 (script.text, Testing, JSON/DB, Productivity)02/26/15
Support this week's primary sponsor:
Just this past week, I discovered the text property that is available on any script element in an HTML page. I'm surprised I haven't come across this before, and maybe you're in the same boat.
Let's say we have the following HTML:
Example text inside a script element.
<!-- comment test -->
<p>Example text inside a script element.</p>
Here we have 3 script elements – two with a src attribute set. I've also added a class to each, so I can collect them all without worrying about grabbing other ones I don't want when creating the demo page.
Notice that 2 of the script elements have some content included, the last one also including an HTML comment and paragraph tags. The text property for script elements allows us to grab the contents of the script element, similar to how the textContent property works on regular elements. In his Definitive Guide, David Flanagan says: "This makes a script element an ideal place to embed arbitrary textual data for use by your application." I've heard of developers using hidden textarea elements for this sort of thing, but not a script element.
So our code to grab the text might look like this:
var scripts = document.querySelectorAll('.sc');
And of course, I could store those values wherever I want, but in this case I'm just outputting them to the console. See this demo to test it out, and notice that in that demo, I'm also defining the text content for the 2nd script element, then outputting that after it's set. So it's not read-only.
The stuff I've read on this property, however, seem to be a little contradictory and confusing, and there's definitely a bug in Chrome. Here's a description of my findings:
Maybe I'm misunderstanding something about this property, but I'm going to do some further testing and then I'll file any bug reports with the browsers. If you have any further info, feel free to reply to this email.
- Flanagan seems to imply that the text property is available only on script elements that don't have a src attribute set. My demo disproves that in the 3 main browsers (although maybe I'm just misreading what he says).
- The spec says this property "must return a concatenation of the contents of all the Text nodes that are children of the script element (ignoring any other nodes such as comments or elements), in tree order", however, all 3 browsers return the paragraph element in my demo and Chrome also returns the comment.
- Bugs aside, I believe this property is supported in all browsers, even back to old versions of IE.
Now on to this week's tools!
Testing and Debugging Tools
"Gather feedback where it matters most. Create better websites by getting opinions in context: in the browser."
Web Font Load
"The easiest way to install all of the Google Web Fonts on OSX."
"Automated Visual Testing and Monitoring. Get notified when your web design breaks."
Cross Browser Testing
"Cross browser test your website in dozens of browsers with instant results. Over 1,000 combinations of browsers, OS, and plugins."
"An on-screen debugger/logger and (optionally) default browser console replacement. Konsole was created to have a quick and simple way to debug a project you are working on, without the need to have a debugger take up precious space."
"Videos of real people speaking their thoughts using your website, app or prototypes."
"Debug all the POST requests. Not sure what's getting POSTed? Simply point your code or web-hook to a unique POSThere.io URL, then open it in your browser to see exactly what was POSTed."
Punch in a URL and this service will tell you what technologies the website is built on.
|Support Web Tools Weekly: 384 pages of CSS for $7
Documents, Content, Files, etc.
"A file‑based CMS. Easy to setup. Easy to use. Flexible as hell."
"Simple, ready-to-go charts." Just punch in the data in tabular or JSON format, and then download a PNG of the data visualized.
Ozh' Tweet Archiver
"Import and archive your tweets with WordPress."
Send To My Cloud
"Make a web page that lets people upload pictures, videos, PDFs, documents, proposals (and anything else you can think of) directly to your Dropbox or Google Drive."
A private, encrypted messaging service that destroys the message after it's read, or after 7 days.
"Generate OPML files from Markdown."
"The most comprehensive and powerful web scraping solution yet invented. Cloud-based."
"Supervises websites and notifies you when your desired content hits the web."
Open source note-taking and archiving alternative to Evernote, Microsoft OneNote, and Google Keep.
"Get a daily email with the most recent follows and favorites of five Twitter users of your choice."
"Task management software for devs and designers."
"Beautifully simple business travel and expense management."
"You need a new email app. One that's just for writing emails."
"Communicate with your clients and co-workers more efficiently with screenshots." Also allows annotations for providing feedback.
iOS app. "Hate typing the same thing over and over, one key at a time? Personalize and pre-program your keyboard with WordBoard. Now you can control what the keys input."
|Support Web Tools Weekly: 384 pages of CSS for $7
A Tweet for Thought
Suggestions / Corrections
Made something? Send links via Twitter @WebToolsWeekly (details here). No tutorials or articles, please. If you have any suggestions for improvement or corrections, feel free to reply to this email.
Before I Go...
Believe it or not, this week I finally tried out Spotify (I still own CDs, for crying out loud!). Hackers who are also Spotify users might enjoy this Spotify Playlist Downloader.
Thanks to all for subscribing and reading!