# Viewing "Source" (on a web page)

**URL:** https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836
**Category:** Factual Questions
**Created:** [July 21, 2003, 2:34am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836 "2003-07-21T02:34:50Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![KarlGauss](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/karlgauss/32/3713_2.png) [@KarlGauss](https://boards.straightdope.com/u/KarlGauss)
#### Post date: [July 21, 2003, 2:34am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/1 "2003-07-21T02:34:50Z")

</div>

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]

---

<div class="post-metadata">

### Author: ![Q.E.D](https://avatars.discourse-cdn.com/v4/letter/q/51bf81/32.png) [@Q.E.D](https://boards.straightdope.com/u/Q.E.D)
#### Post date: [July 21, 2003, 2:39am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/2 "2003-07-21T02:39:07Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Mister\_Rik](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mister_rik/32/491_2.png) [@Mister\_Rik](https://boards.straightdope.com/u/Mister_Rik)
#### Post date: [July 21, 2003, 2:39am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/3 "2003-07-21T02:39:15Z")

</div>

1. 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).

2. 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?”

3. 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.

---

<div class="post-metadata">

### Author: ![yabob](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/yabob/32/2821_2.png) [@yabob](https://boards.straightdope.com/u/yabob)
#### Post date: [July 21, 2003, 2:58am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/4 "2003-07-21T02:58:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aahala](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@aahala](https://boards.straightdope.com/u/aahala)
#### Post date: [July 21, 2003, 3:07am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/5 "2003-07-21T03:07:05Z")

</div>

Near the top of the coding on many pages, there is information about the page, author, software or comments about the page or topic.

---

<div class="post-metadata">

### Author: ![Una\_Persson](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/una_persson/32/346_2.png) [@Una\_Persson](https://boards.straightdope.com/u/Una_Persson)
#### Post date: [July 21, 2003, 4:39am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/6 "2003-07-21T04:39:12Z")

</div>

…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.

---

<div class="post-metadata">

### Author: ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)
#### Post date: [July 21, 2003, 10:25am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/7 "2003-07-21T10:25:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jjimm](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jjimm](https://boards.straightdope.com/u/jjimm)
#### Post date: [July 21, 2003, 10:43am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/8 "2003-07-21T10:43:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)
#### Post date: [July 21, 2003, 11:16am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/9 "2003-07-21T11:16:04Z")

</div>

> [@](#):
>
> \*Originally posted by jjimm \*  
> \*\*Code theft. Er, I mean “reference”. \*\*

Eh, why reinvent the wheel?

(I know about copyright laws. I also know how to get work done.)

---

<div class="post-metadata">

### Author: ![AHunter3](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ahunter3/32/368_2.png) [@AHunter3](https://boards.straightdope.com/u/AHunter3)
#### Post date: [July 21, 2003, 7:01pm UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/10 "2003-07-21T19:01:49Z")

</div>

The page referenced in the thread [The Cost of the War](http://boards.straightdope.com/sdmb/showthread.php?threadid=199020) 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](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

> [@](#):
>
> \<!-- Welcome Visitors: I made every effort to make the javascript accessible.  
> Please feel free to load costofwar.js to view it. --\>

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:

> [@](#):
>
> Statement on line 82: Expression evaluated to null or undefined and is not convertible to Object: document.getElementByld(“raw”).firstChild

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:

> [@](#):
>
> // run this function again in 100 milliseconds  
> setTimeout(‘inc\_totals();’, 100);

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.

---

<div class="post-metadata">

### Author: ![KarlGauss](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/karlgauss/32/3713_2.png) [@KarlGauss](https://boards.straightdope.com/u/KarlGauss)
#### Post date: [July 22, 2003, 2:20am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/11 "2003-07-22T02:20:24Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Larry\_Mudd](https://avatars.discourse-cdn.com/v4/letter/l/f14d63/32.png) [@Larry\_Mudd](https://boards.straightdope.com/u/Larry_Mudd)
#### Post date: [July 22, 2003, 2:44am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/12 "2003-07-22T02:44:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DaveW](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DaveW](https://boards.straightdope.com/u/DaveW)
#### Post date: [July 22, 2003, 2:52am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/13 "2003-07-22T02:52:39Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![SmackFu](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@SmackFu](https://boards.straightdope.com/u/SmackFu)
#### Post date: [July 22, 2003, 4:53am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/14 "2003-07-22T04:53:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Some\_Guy](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Some\_Guy](https://boards.straightdope.com/u/Some_Guy)
#### Post date: [July 22, 2003, 5:37am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/15 "2003-07-22T05:37:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Achernar](https://avatars.discourse-cdn.com/v4/letter/a/e274bd/32.png) [@Achernar](https://boards.straightdope.com/u/Achernar)
#### Post date: [July 22, 2003, 7:05am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/16 "2003-07-22T07:05:12Z")

</div>

> [@](#):
>
> \*Originally posted by KarlGauss \*  
> 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.

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. 😛

---

<div class="post-metadata">

### Author: ![yabob](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/yabob/32/2821_2.png) [@yabob](https://boards.straightdope.com/u/yabob)
#### Post date: [July 22, 2003, 3:16pm UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/17 "2003-07-22T15:16:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![aahala](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@aahala](https://boards.straightdope.com/u/aahala)
#### Post date: [July 22, 2003, 4:38pm UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/18 "2003-07-22T16:38:04Z")

</div>

> [@](#):
>
> \*Originally posted by DaveW \*  
> 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? \*\*

I noticed a thread about this at [webhostingtalk.com](http://webhostingtalk.com) today.  
The solution was to clear cache.

---

<div class="post-metadata">

### Author: ![Cervaise](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cervaise/32/16693_2.png) [@Cervaise](https://boards.straightdope.com/u/Cervaise)
#### Post date: [July 22, 2003, 7:54pm UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/19 "2003-07-22T19:54:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DaveW](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@DaveW](https://boards.straightdope.com/u/DaveW)
#### Post date: [July 23, 2003, 4:19am UTC](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836/20 "2003-07-23T04:19:47Z")

</div>

**aahala** wrote:

> [@](#):
>
> I noticed a thread about this at [webhostingtalk.com](http://webhostingtalk.com) today.  
> The solution was to clear cache.

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**.

[Next page](https://boards.straightdope.com/t/viewing-source-on-a-web-page/189836.md?page=2)
