What is the purpose of being able to view[sup]*[/sup] the (?HTML) source on a web page? Can’t say I’ve ever done anything with it other than stare vacantly.
[sub][sup]* under the “View” pulldown menu[/sup][/sub]
What is the purpose of being able to view[sup]*[/sup] the (?HTML) source on a web page? Can’t say I’ve ever done anything with it other than stare vacantly.
[sub][sup]* under the “View” pulldown menu[/sup][/sub]
I find it useful for getting examples of HTML and javascript coding, and for debugging my own webpages (such as checking to be sure the latest version uploaded successfully), and debugging other people’s pages.
It’s handy for a Web developer to be able to quickly look at his source code while viewing the page, in order to track down bugs. It’s often easier to do this within the browser, rather than trying to view two applications at once (in the browser and in the code editor).
It provides an easy way for beginning Web designers to examine the code of others, to take a look and see “how did he do that?”
If a Web page doesn’t work in my browser of choice, I can look at the code, figure out why it doesn’t work, and send the author an e-mail to tell him about the problem and suggest a way to fix it.
WAY too many uses to mention.
Primarily intended as a diagnostic, so you can see what particular HTML / javascript construct is generating the undesireable display on your browser. This is obviously useful as a debugging aid for the developer, particularly if heavily dynamic content is being generated, and the first step is to confirm what the browser is actually getting.
It can also allow informed reports by users - “the table containing … doesn’t display right for me”. “I can’t see any of the text because you set the font to the same color as the background color of the table cell.”, etc.
Even if you only have a modicum of HTML knowledge it can be useful for doing things like looking up links which you know are supposed to be there, but your browser won’t let you click on for some reason.
Near the top of the coding on many pages, there is information about the page, author, software or comments about the page or topic.
…and sometimes some of those HTML comments range from the quite juicy to the absolutely scandalous. :eek:
Sadly, nowadays I often look at the source to see why a particular trojan or embedded advert is causing woe on a computer.
Finally, and the most important reason, is to help you learn a little something about computer languages. No, HTML is not a programming language*, but it is still a usable way to acquire a bit of knowledge about how computer programs interpret the world. HTML is tokenized and it has a distinct grammar, two things it shares with nearly all real programming languages. More abstractly, HTML is a non-natural language humans invented to talk with computers that is simple enough for the layman to understand with minimal preparation. That alone can get one’s feet wet in the concept of software creation.
*A programming language is a way to describe an algorithm that operates upon data. (Remember, `Algorithms + Data Structures = Programs.’ (Wirth)) HTML describes a document that operates upon … well, nothing. A program operates upon it.
Of course, HTML isn’t the only thing a web page could contain. Both Java and JavaScript pop up (literally, sometimes) in otherwise HTML-filled sources. Java is a real programming language, and JavaScript somewhat less so. (Both are better than BASIC, IMHO. :D) So reading the sources to some webpages could be more educational than just an excursion into the realm of document markup.
Code theft. Er, I mean “reference”. Double-checking my source code. Debugging. Sourcing images and other files. Finding broken links.
I wouldn’t be able to do my job without it.
Eh, why reinvent the wheel?
(I know about copyright laws. I also know how to get work done.)
The page referenced in the thread The Cost of the War comes up with error messages about needing to have JavaScript enabled when I try to view it in my default browser iCab or in Opera 6.
I do of course have JavaScript enabled, so I did a quick View Source to see what’s amiss. Unfortunately, the javascript code itself is in an external file, but I could not see anything in the HTML of the page itself that would keep my browser from referencing the javascript file properly. Couldn’t directly download http://www.costofwar.com/costofwar.js in iCab either, via the standard URL bar or iCab’s Download Manager (which short-circuits browser attempts to render/execute and instead saves specified files to local HD). Hmm, that’s a clue. The HTML specifies it simply as <src=“costofwar.js”>. Included in the line above that is
That would seem to imply that the authors intended that we should be able to access the .js file directly. Back to Opera, which lets me view the .js file onscreen at the above-mentioned URL although it isn’t executing properly. Unfortunately I’m not fluent in Java so I don’t see what’s nonstandard in the code. Opera does, though: I turn on the JavaScript error reporting and reload the page and get:
That would be this line:
[/quote]
document.getElementById (“raw”).firstChild.nodeValue =
“$” + number_str(curamount)
[/quote]
iCab also has a sophisticated error reporter and although it isn’t being allowed to download or display the js code directly, the error report shows it is accessing and trying to parse the javascript in the course of trying to render the page, and the instruction that iCab doesn’t like is on line 94/95:
The usual excuse for sloppy code is that the author threw a couple browsers at it and they did OK on it, so they saw no reason to adhere rigidly to specifications and rules.
I fire up Netscape 6 and sure enough I can load the original page and see the odometer-like “cost of war” calculation incrementing on screen.
In this case, “Show Source” didn’t tell me everything, but it told me enough to guess the rest.
Ah, I see. Thank you.
In fact, I suspected it would be helpful for HTML programmers and people just looking for ideas. I would be surprised, though, if the developers of IE itself (and I assume other browsers) were deliberately trying to help people get coding ideas, learn programming tricks, etc. So, I guess the real reason the option exists is as a debugging aid for the developer (as yabob stated).
Many’s the time I’ve waded through someone’s source code in order to work out where a media file is located so that it can be saved locally – or even viewed at all, if the source in question in sloppy.
Sometimes people put “easter eggs” in the source. I remember a Timothy Leary essay that was hidden (in its entirety) in the source code of his official site. Torn between feeling rewarded for curiousity and outraged at bandwidth wasteage, there.
It’s also useful for the occasional “why the heck did Google return this page as a hit?” View the source, and search for your keywords on that, you can sometimes find 'em in places which a “find in page” either doesn’t find or doesn’t highlight quite right.
A related question, if I may: it seems that IE 6, as supplied by AOL (inertia) has stopped allowing me to view source, ever. This is under XP. It started a couple months ago, when about one out of three attempts at viewing source would simply fail. Now, nothing, ever. Notepad doesn’t even fire up. Any ideas as to the cause of this?
Those are all fine reasons for the feature to exist.
But it could be that there is a “View Source” just because some guy at NCSA put it in Mosaic for the heck of it. And Netscape was based on Mosaic, and IE copied everything useful from Netscape, and all the other browsers copied IE (or Netscape). So it’s just there because it always has been.
Actually, the main reason I ever use the HTML source is to fix up badly-designed pages for easy printing. In particular, it’s always nice to be able to fix up stupid fixed-pixel-width tables.
This isn’t as underhanded as it sounds. They’re not programming tricks because HTML isn’t a programming language. Ideally, the markup of a web document should be available to be viewed however the user wants it. Believe it or not, some people are more comfortable reading a well-designed page as plaintext markup. I’m not one of them, though. Those people are weirdos.
A couple more points.
Another “non-debugging” use is to extract text that you can’t highlight. Occasionally, somebody protects their copyright through using javascript to prevent your cutting and pasting the text on the page. While I respect their copyright, there are many legitimate reasons to clip their text that don’t violate it, and I think doing this counts as annoying. You may be able to clip their text from the “view source” screen.
It was also useful to get all the links out of image maps without having to wander around the image clicking. These days, most browsers have other informational displays that include a list of the links on the page you are viewing.
Some web designers would like to be able to prevent source viewing, particularly of javascript - they may not wish to show you how they coded a particular feature. Fortunately or unfortunately, depending on your point of view, most techniques to prevent it don’t work all that well.
However, another old solution is sometimes used. You can buy javascript “obfuscators” to screw up the code appearance, making it that much harder to figure out what it is doing. I think this has been done for every programming language which has enjoyed commercial use.
You can also buy some HTML protection products which turn your document, or sensitive parts of it, into an encoded stream to be decoded and evaluated with javascript. It should be noted that somebody may be using this to prevent things like autoharvesting of email addresses by robots, not just to prevent source viewing.
I noticed a thread about this at webhostingtalk.com today.
The solution was to clear cache.
About a week ago, I was trying to submit information on a web form. It wasn’t working. I viewed source and reviewed the page, and while I couldn’t identify the problem, I was able to get the email submission address to which the form was supposed to be sending its data. So I picked through the fields collected by the form and built a text file that would look approximately like what the form would have made, and I sent it to the email address in the code.
I don’t view source often, but I’m very happy it’s available.
aahala wrote:
I told IE 6 to delete its “Temporary Internet Files,” and after about 10 minutes of disk-grinding, I can view source again. “Temporary” my Aunt Fanny!
Thank you very, very much, aahala.