Sep 27th, 2008 by Daniel | 1 Comment »
I’ve posted about using JavaScript to detect specific browsers, but that script seems to have its limitations. I’ve become infinitely more comfortable with PHP in recent years and find that the following is an acceptable option for detecting a browser. Better yet, you can write code that will change depending on your visitor’s browser. In this case, I use it to switch CSS files. Here is the code:
<? // check for UA, convert UA string to lower case
$navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
// Check browser and select CSS file
if (stristr($navigator_user_agent, "msie 6")){
echo '<link href="css/alternate.css" rel="stylesheet" type="text/css" />';
}
else{
echo "<link href='css/style.css' rel='stylesheet' type='text/css' />";
}
?>
If all went well you should now have a script that selects an alternate CSS file for your IE6 visitors. You can use else-if statements if you would like to add more contingencies. Another upside to this is if you’re using non-valid CSS (like *html for IE) you can shuffle it all away in another file that the W3C validator will never see. Devious!
Make sure you find your user agent string! Some of these are similar and will contain the names of other browsers, so be specific when you use a keyword to search the UA string.
Posted in PHP, HTML, how-to | 1 Comment »
Nov 15th, 2007 by Daniel | No Comments »
I’ve always had problems with folders that start with ‘The,’ as it places the folder under ‘t’ when arranged in alphabetical order. I’m really big into using file directories for my media, and as the computers at my work use scripts for all kinds of redundant operations, I it would be a good challenge to make one of my own. This is pretty simple; I’ll get more in-depth with scripting as I go.
Create a new text file, copy the code into the file, and rename it to .vbs Don’t forget to change the directories and string fields to suit your needs. I’m not too big on VB, so I modified another script to get me started, but the search and replace functions are specific to our job (rearranging ‘the’ in the folder name).
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("z:\Movies")
RenameSubFolders(oFolder)
set oFolder = Nothing
set oFSO = Nothing
Function RenameSubFolders(myFolder)
For each oSubFolder in myFolder.SubFolders
dim pos
pos=InStr(oSubFolder.Name,"The ")
If pos = 1 Then
oSubFolder.Name = Mid(oSubFolder.Name, 5) + ", The"
RenameSubFolders(oSubFolder)
End If
Next
End Function
This script searches for a string in a folder name and places it at the end of the said folder name. So, for instance, I have a ton of folders named “The (MovieName)” This script renames them to “(MovieName), The”. Like I said, I’m old school and use file directories for everything (no I-Tunes, thank you) so alphabetical order is very important. Rather than taking the hours to rename a bunch of folders, I took an hour to toy around with some Visual Basic. Totally worth it.
So in the end, I really don’t understand why people don’t use scripts more often, especially for the growing media libraries that most people have on their computers. I guess it all comes down to I-Tunes and similar applications.
Posted in scripting, Windows, how-to | No Comments »
Aug 15th, 2007 by Daniel | No Comments »

I finally got Linux running in Windows so I can test on Konqueror. As I suspected, it worked about the same as Safari, another KHTML browser. Anyway, the easiest way I found to get Linux running in Windows can be found here. It’s just a matter of running KMD on a virtual machine. I originally tried to get it to run using Cygwin, which was a waste of time.
Another issue I ran into a while back was testing with IE6 and below. Having two versions of Explorer on the same OS is nearly impossible. Microsoft released a VPC image running IE6 for this reason. It is available here.
And if you haven’t heard yet, a beta version of Safari 3 is available for download. You can get it here.
Posted in Windows, how-to | No Comments »
Aug 13th, 2007 by Daniel | No Comments »
Modify the Document Type Definition (DTD)
Many of the best AJAX apps activate by using custom triggers that do not qualify as valid HTML. I used to think that all was lost, and that there was a mandatory trade between functionality and usability. This is not so: doctype information may be appended to include your triggers.
For instance, I use a modal window system called LightWindow that has “author” and “caption” triggers to relate data to the script when a user clicks on an image. Neither of these triggers will validate under the XHTML 1.0 DTD. Here’s the code to fix it:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
[
<!ATTLIST a author CDATA #IMPLIED>
<!ATTLIST a caption CDATA #IMPLIED>
]>
This is how it breaks down:
<!ATTLIST element attribute dataType #IMPLIED or #REQUIRED>
Since my elements relate to linked files e.g.(<a href=) that I want to open with LightWindow, I use the element ‘a’ for link. The attribute is what you are using to communicate with your app and is also what is causing your document to not validate. The dataType can likely just be left as CDATA as it handles any kind of data. It is also likely best to leave the type defenition as #IMPLIED or optional for these purposes. A more in-depth article can be found at A List Apart.
Fix invalid symbols by changing them to HTML
If you are using a script in your document that is called using symbols such as the ampersand ‘&’ or equals ‘=’ these will cause the validator to choke. Consider using their HTML forms amp; and #61; (with ampersands in front) respectively. A complete list of symbols and HTML translations is available at the Web Design Group’s site.
For example, a line on my site used to look like this:
<link rel=“stylesheet” type=“text/css” href=“combine.php?type=css&files=dlinn.css,lightWindow.css” />
But now looks like this:

Still having problems with CSS?
Yeah, me too. We’ll just have to hang in there until the newer standards (that have existed for years) are adopted or hell freezes over.
Posted in HTML, how-to | No Comments »
Aug 8th, 2007 by Daniel | 7 Comments »
So you have your site running on the latest and greatest Java libraries, but your supporting CSS and JavaScript files are really starting to slow things down. You’re no JavaScript expert, so what do you do? Lucky for us some other people have already encountered this problem and have a great solution.
Make your pages load faster by combining and compressing javascript and css files
The site itself describes in great detail how the script works. It took some trial and error for me to get this thing working, so here are some tips:
- If your site’s root folder is in another directory on your server, make sure you create an .htaccess file in that directory. There may be an .htaccess file in your public_html folder already, but unless that is your site’s root folder, you should not change it. Once you edit and place this file in your site’s root, all CSS and Java files accessed in their respective directories will be redirected to the combine.php script.
- With the .htaccess file in mind, you need to place your combine.php file in the same directory, or edit your .htaccess file to point to combine.php.
- Combine.php will compact and compress your files and send them to a cache folder that you need to create, again, in your site’s root directory. This way the client’s browser will access the cached files and wont request new files needlessly.
- Once you have everything in place, you need to call your files in a way that the combine.php script recognizes. Here’s an example:
<script type="text/javascript" src="combine.php?type=javascript&files=prototype.js,effects.js,lightWindow.js"></script>
If everything went as planned, you will use less bandwidth, your site may load a bit faster and your visitors will never know.
Posted in java, how-to | 7 Comments »
Aug 8th, 2007 by Daniel | No Comments »
Learning how to write code can be tough. I was first introduced to AJAX (asynchronous JavaScript and XML) when building a website for a friend and artist. I learned to love Web design but found most employers want the full package; half artist, half logical programmer. So I set out to learn JavaScript and its uses. Anyway to wet your palate, I have included a few links that got me interested in learning JavaScript.
MiniAjax.com (careful, this loads a bit slow)
MooTools
Prototype (doesn’t play with MooTools; see moo.fx)
Lightbox
If you are a Web standards kind of person, you’ll know what I mean when I say AJAX is leaps ahead of Flash. I am still reluctant to learn action script for this reason, but that will depend on my future employer’s preferences (a whole other can of worms). When AJAX is implemented properly, client computers can have JavaScript completely disabled but they will still load all the content that the gracious Web developer hath provided them; they will only forfeit smooth Java-powered navigation. Try that with Flash.
So here I am trying to make myself more marketable by learning how to code JavaScript and PHP for the sake of creating my own AJAX apps. Lucky for us, there is a lot of information online and in local bookstores. I have compiled a small list of reading for people like me who do not come with a computer science degree. I’ll try to keep most of it online, but for your sake I suggest you go to a bookstore, grab some java coffee (ok, that was lame) and a Java/AJAX book. There should be plenty. I like to use a notepad and rewrite anything I’ll need to know. It saves money and it’s a great way to learn.
W3C Schools
AjaxLessons.com
Rasmus’ 30 second AJAX Tutorial
AJAX for Dummies (See also Java and XML for Dummies)
Ok, that’s all for now. I will continue to post what I find in hopes that someone out there will learn with me. We’re in this together.
Posted in java, how-to | No Comments »