You learn something new every day: 404.html file size issues?

I found this in a friend’s 404.html file:

< !-- - Unfortunately, Microsoft has added a clever new - "feature" to Internet Explorer. If the text of - an error's message is "too small", specifically - less than 512 bytes, Internet Explorer returns - its own error message. You can turn that off, - but it's pretty tricky to find switch called - "smart error messages". That means, of course, - that short error messages are censored by default. - IIS always returns error messages that are long - enough to make Internet Explorer happy. The - workaround is pretty simple: pad the error - message with a big comment like this to push it - over the five hundred and twelve bytes minimum. - Of course, that's exactly what you're reading - right now. -->

Does anyone know if that is still the case? I haven’t come across this before, but it is sure worth knowing about even if it is ie6 specific…

Don’t use YourDomain.com or MySite.com in your examples

Every time you type one of those urls, some domain parking twit gets another link to their site and who knows how many more hits.

The Internet Assigned Numbers Authority (IANA) has reserved an url or two specificly for examples.

If you use Example.com, Example.net, Example.org, or Example.info you are not going to be helping deliver traffic to someone you don’t know anything about. These four Example.TLD (top level domain) addresses are IANA_RESERVED and you can use them safely.

Note that other example sites like .US .be .dk .de .co.uk etc are all owned by different companies. Only use the four mentioned above.

How to get around “Access is Denied” in a Window.Open() JavaScript call

I’ve made two changes to the Forms and Field lister I posted yesterday – the original post has been altered to include them.

First and foremost, the line to paste into Start->Run to install the program into the registry was being altered by WordPress. Though the text looked identical, the double quotes were being changed to a different character. The result was you would receive an “invalid key name” error. If, in DOS, you went back and replaced the double quote imposters with actual double quotes, it would run fine. So I have wrapped that line with PRE and TT tags in the original post and provided a batch file in case anyone still has problems.

Second, it was discovered that some Windows computers would block the popup. There would be no error given or any indication of what happened beyond a dialog box flashing up on the screen and disappearing. I debugged this by adding alert(1),alert(2)…alert(n) messages after every line of the source code. Once I did that, IE was kind enough to tell me that it was bombing out due to an “Access is Denied” error triggered from my Window.Open(“”,”tcc_formlist”,””); command. That line worked at my office, but bombed out on one of my home computer.

The reason is that Windows now blocks one window or frame accessing another window or frame that is in a different domain (or security zone I believe). This technique is calls Cross Frame Scripting. The problem is that what I am doing with these tools IS exactly working across two frames/windows. Luckily there is a way around this.

The JavaScript Mini-FAQ, available here: http://www.dannyg.com/ref/jsminifaq.html#q15, has a good description of this issue and the work around:

Q. What does the IE “Access is Denied” error mean?
A. The “Access Denied” error in any browser usually means that a script in one window or frame is trying to access another window or frame whose document’s domain is different from the document containing the script. What can seem odd about this is that you get this error in IE for Windows frequently when a script in one window generates a new window (with window.open()), and content for that other window is dynamically created from the same script doing the opening. The focus() method also triggers the error.
The error can also occur if scripts try to access objects, properties, or methods that have been locked down by Microsoft’s security platoon. For instance, the document.styleSheets.rules property used to be accessible in IE 5 and IE 5.5, but is not in IE 6.

For the new window problem, there is a bit of history associated with the problem and workarounds. For example, the problem occurs frequently when the scripts are being run from the local hard disk. You get a clue about the situation in the titlebar of the new window: It forces an about:blank URL to the new window, which is a protocol:domain that differs from wherever your main window’s script comes from. If, however, you put the same main window document on a server, and access it via http:, the problem goes away.

There is a workaround for the local-only problem: In the first parameter of the window.open() method call, load a real document (even if it is a content-free HTML document) into the sub-window before using document.write() to generate content for the subwindow. The loading action ‘legitimizes’ the window as coming from the same domain as your main window’s document.

(This solution does not affect scripts that load a page from a secure server into a separate window or frame. An http: protocol in one window and https: in the other–even if from the same server.domain–yield a security mismatch and “Access Denied.” Setting the document.domain properties of both pages may solve the problem (but I am unable to test it for sure).)
[…]

I’ve updated the original code to include this fix.
Window.Open(“”,”tcc_formlist”,””);
is now
Window.Open(“file:///c:/Windows/web/formlist.htm”,”tcc_formlist”,””);

The end result is that window.open command quickly opens the script before the dynamic content is displayed. This little blip is not noticeable on my daughters computer. I don’t think it will be a major slowdown. Due to how the code is written, the whole of the JS routine is not executed. The biggest negative is that the script now has a reference to what I expect the file name to be on your computer. If you rename the script, you need to change that reference in the source. I doubt many people will rename the script.

That was kind-of a ramble… Does that all make sense?

Listing the Forms and Fields on a page in Internet Explorer or Maxthon

This post is an introduction to what I’ve been researching in my spare time over the last few weeks. It will be the first in a series of posts about form submission. It will lead you basically along the path that I took in discovering this information, and will hopefully allow you to skip over some of the trouble spots along the way. I’ll note each of the trouble spots in the comments in the doc (for instance in this one I include a note about the value of a button also being submitted with the form).

This HTML file builds on top of the work that I did on with the Copy as Text Link tool referenced elsewhere on this site. However, this routine processes the currently active webpage/frame and generates a report of the Forms and fields on that page. For each form it shows its name, action and then list the inputs on that form. For each input, it shows its name and value. From this information, you can see what is being tracked between pages on a website. You could also use this information to debug an entry form you are creating. It could also be used to generate the form submission information that will be generated by a certain action so that it can be repeated programmatically in the future.

This routine will only work in IE right now and older releases of Maxthon. It could easily be transposed to other browsers and tools. The process should be relatively easy to follow thanks to Microsoft’s Document Object Module (DOM) technology. DOM allows HTML code to be accessed as if it were Object Oriented. In other words, this routine doesn’t work with the HTML source code. Instead it asks IE for specific parts of the webpage one at a time. This allows each of the various parts/divisions of any web page to have its own particular properties and methods. This routine asks asks the document object for the list of forms it contains. It then asks each form for a list of fields. It displays each in its turn.

To install this file in IE, right click on the following link and choose Save Target As. Then in the destination window type %WINDIR%\web\formlist.htm and press enter.

RIGHT CLICK THIS LINK

%windir% is an environment variable that represents your Windows directory. So you can put C:\Windows\Web\formlist.htm if you know you have a c:\Windows directory.

Then choose Start->Run and put in this text and then press enter:

reg ADD "HKCU\\Software\\Microsoft\\Internet Explorer\\MenuExt\\F&orms and Fields" /ve /t REG_SZ /d "%WINDIR%\\web\\formlist.htm" /f


That will update your registry to point to the file. If you have problems, use this batch file instead. It contains the same command but will not be corrupted by windows.

Then close all instances of IE.

Now browse to a web page that has a form, most of them do now-a-days.

Right click anywhere on the text of the form and choose Form and Fields from the menu.

You’ll now be able to see all sorts of information about the page you were on and the fields and hidden fields it contains.

BTW, this routine uses a pop up window. Popup blockers like the Google Toolbar will try to block this form. So, you just might have to hold down the CTRL key as you choose Form and Fields to allow this to work.

Also, FYI it works in Maxthon through at least version 1.5.2 build 21. I think build 23 reworks the context menu stuff, but don’t quote me on that.

Enjoy!

Sample output from FoxNews.com

(Source code follows)
NOTE: There is now a reference to the final location of this file in the source code. If you install this as something other than c:\windows\web\formlist.htm you must now update the source code.

Continue reading Listing the Forms and Fields on a page in Internet Explorer or Maxthon

Copy To Clipboard in HTML

or Speed blogging Exposed…
or “Copy as Text Link” and “Copy as Image Link” Blogging Tools explained.

Usually when I post something technical, I include a detailed rambling explaniation of how it does what it does. In the post “Copy as Text Link” and “Copy as Image Link” Blogging Tools” I created a batch file that did some neat stuff. But I didn’t give a full explaination of the details. Now I will.

The batch file did the following neat stuff…
1. Used Environmental variables to create HTML files in a standard Windows directory
2. Dynamically add string and DWord registry entries
3. Demonstrated adding menu items to Maxthon & Internet Explorer (Unfortunatly these do not show up in FF or Opera.)
4. Displayed different contexts based upon what was selected.
5. Launched another IE window that does not effect the output but does process information selected in the first.
6. Demonstrated how to copy HTML source to the paste buffer via HTML and javascript.:
7. Copied text to the clipboard, formatting it into HTML

Not bad for a small batch file.

So, here’s how the magic was done…

First, the easy stuff. The batch file creates two text files. That is done using the redirection symbol (aka the output to file symbol) which is > (aka the Greater Than sign). The Greater than sign appends the displayed results directly to a file. Two greater thans in a row cause the file to be recreated. I use the Echo command to echo (go figure) text to two HTML files I will be creating. Since I use >> in the first line, those files will always be recreated if the batch file is run again.

Because HTML also uses GT and LT symbols, they must be denoted as literal symbols. That is done with the carot symbol ^. Thusly
[dos]
echo ^>%windir%\web\copytextaslink.htm
echo ^

[/js]

As you can see, the bulk of the file is JavaScript. The second line clearly declares it so. However, instead of putting Language=”JavaScript” (which is the old school way of doing things and how I learned originally), I should have specified it as a MIME type like this Type=”text/javascript” The end result is the same, however eventually the old language option will be dropped.

Another option that you might not be familiar with is the defer flag. This is a browser load time optimizer. It tells the browser that the contents of the script will not effect the layout of the page and therefore the browser can continue drawing the page.

The process is also pretty easy to follow because it uses Microsoft’s DOM technology. DOM is the Document Object Module and allows IE to handle all web pages as if it were Object Oriented. You can reference the document and the various parts/divisions of any web page. And that allows you to directly access properties or methods of these objects.

So what the code above does is asks for the document in the parent window (the one in which you right clicked). It then asks for the current selection (if any). It then gets the current selection as text and then asks for the clibboard object for the current window. At that point it is a simple call to SetData and the selected text is added (with a few additions) to the clippboard. There isn’t much more than that. One thing that should be noted is that the type of data in the clibboard must be specified, in this case, as text. You can read more about the other types of data that a clib board can handle in my article about Clipboard manipulation with Delphi HERE:

The second file proceeds much the same way except that it goes further into the DOM and retreives the Height and Width of the original image so that the pasting of the tag in your blog can include that information (most specifically, the aspect ratio.

[js]


[/js]

That’s it for the HTML. The only thing left is to create a couple of triggers to activate those two files. That’s done through the registry.

Internet explorer reads through the registry each time it pops up a menu. It first decides what is clicked and then looks at the registry entries under HKey_CurrentUser\Software\Microsoft\Internet Explorer\MenuExt\ all of the menu items that match the type of selection. MSDN has a full article that explains this in detail HERE, however, the following table is probably all you’ll need:

Context Value
Default 0x1
Images 0x2
Controls 0x4
Tables 0x8
Text selection 0x10
Anchor 0x20

So, the last step of the process is to route the text to the text processing HTML and the img tag source to the image text file.

That’s done in these two lines…
[dos]
reg ADD “HKCU\Software\Microsoft\Internet Explorer\MenuExt\Copy Image as Lin&k” /ve /t REG_SZ /d “%WINDIR%\web\copyimageaslink.htm” /f
reg ADD “HKCU\Software\Microsoft\Internet Explorer\MenuExt\Copy Image as Lin&k” /v Contexts /t REG_DWORD /d 2 /f
.
[/dos]

That’s it! You’ve got your full walk through! Any questions?

“Copy as Text Link” and “Copy as Image Link” Blogging Tools

Justin of JustInsomnia had a great idea for a FireFox plug in:

I want to be able to copy a quote and its URL at the same time, without having to so much as think about it. To do so, I wrote my first Firefox extension, which I opted to name the somewhat homely, Copy as HTML Link.

So he created Copy as HTML Link for Firefox and generously shared his moment with wp-hackers Subscribers .

The plugin looks good and he did a really good job documenting it (THIS IS RARE!):

Click to go to the original site.

I must say that since I’ve started using this method, it’s been a quite a time saver. This was a GREAT idea. Inspired! So, if you have FireFox, please head on over there and get that plug-in!

Ah, but here’s the fly in the ointment and the sand in my… socks: A Firefox plugin won’t work for Maxthon!!!! (Click to go to the original site.) or Internet Explorer!

You see, Firefox just doesn’t do it for me. Click to go to the original site. Opera comes darn close to being right, but I like the extra usability features in Maxthon.

So, I thought… Hey… I could do that for Maxthon and IE AND I could do it all from a BATCH file!

So, here it is…

Run this Batch file and you will have installed on your system, two new menu items. When you highlight text, you’ll have an option to “Copy as Link” and when an image is right clicked, you will get an option to “Copy Image as Link”. Hopefully I’ve chosen hotkeys that will work well for you… If not, you can change them in RegEdit at HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\

BTW EVERY image and link up to this point in this post was created using this tool. Man, Good idea Justin!

Also – If you find that IE is prompting you asking for permissions to open the links, please post a comment and I’ll show how to fix that. I’ve gotten that message on other things I’ve like this I’ve created and know how to get past it. I’ve disabled that workaround on this computer and I am not getting that “Are you sure” message. So these menu items should be safe. ALSO, some popup blockers may block these items. You might have to add localhost as a site that is allowed to show popups in your particular popup blocker. Let me know if you have any problems.

Here’s the download: http://www.TheCodeCave.com/downloads/batch/AddCopyAsLink.bat

Here is the source:
[DOS]
@echo Off
:: Implements “Copy * as Link” menu items in IE and Maxthon
:: Written by Brian Layman
:: Visit me at: http://www.TheCodeCave.com
:: Version 0.1
:: Update Url: http://www.thecodecave.com/?p=152
:: Inspired by Justin’s Firefox Plubin
:: Found at: http://justinsomnia.org/2006/05/copy-as-html-link-for-firefox/

:: Create file for the Copy Text as Link
echo ^>%windir%\web\copytextaslink.htm
echo ^

216 colors that don’t REALLY matter any more

This table is now only good for a quick lookup of colors. For a few short years it was known as the WebSafe 216 colors. These were the colors that you were suposed to use on your website in order to GUARANTEE that your site would look exactly the same on every computer and with every browser out there. These colors were invented when everybody was only using 256 color monitors. And most monitors and video cards did not allow you to adjust the RGB values. Now however, because no one surfs in 256 color mode any more and everyones monitor contrast is set differently anyway, this color scheme is relatively useles as far as websites are concerned. That said, people STILL try to promote its use and if you are reading this article, now archived, someone probably told you the same thing.

Don’t listen. Make your site plain and simple. If you are using colors that MUST be displayed exactly right for your text to be readable, then you are doing something wrong. Contrast, to a certain extent, is a good thing.

Others, like me, might just want to look up some colors in HEX because you don’t know their official web color names. That’s why this has got a spot in the code cave. If I need a number, I follow the link at the end of this post…

BTW Color names are a myth too. I know there’s a wonderful page out there that has all sorts of colors that work in IE and some other browsers, Colors like “Dark Orange” or “Silver dew on yellow marigolds”, but that’s all a myth too. There are only 16 official web color names. Anything else is added on by the browser’s developers and who knows what color you’ll get if Use hex instead of any color name that is not: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, or yellow.

The 216 Web safe pallete color lookup table can be found here.

Now, go add some color to your life!