Programming for the Web
In this blog I hope to provide information to aspiring web designers, and web developers looking for answers to technical problems. It also serves as an archive of solutions I have found, for myself.
Friday, May 4, 2012
Div Height and Width Properties
Height and width style sheet properties can be tricky, but it is something that all web developers need to have a firm handle on.
Monday, December 19, 2011
Creating a Subdomain
Please Note:
I have done tests on two different computers, and the results were the same. Please comment on any problems you may have. Becarful when adding comments to your directives, comma's and dots may cause issues with the directives.
One of the most difficult things to do when you are building a website, is to make a sub domain. A sub domain is written as, sub domain.domain.com.
You can think of it as a virtual domain. It is simply a server instruction that directs the user to a directory off of the domain you pay for, such as domain.com/example.
I just recently learned how to do this, and decided to take some time and document my findings. It wasn't easy. I must of spent half the day researching.
To create a sub domain follow these simple instructions;
1) Setup a sub directory.
2) Add a htaccess file to the root of the domain.
3) Configure the htaccess file to accept the following url, subdomain.domain.com
That's it folks. Its really that simple.
The only part that is not simple is configuring the htaccess file. Do it carefully, and it will work the first time.
The .htaccess file provides a way to make configuration changes on the server (on a per directory basis). A file that contains one or more directives is placed in the root directory, and the directives apply to that directory, and all sub directories bellow it.
If you have never used this file before, it can be quite daunting. The commands are not easy to learn, and you won't use it very much except for very specific tasks, like redirecting someone form one file to another. Its like being in command of the server, without being in total control.
Information on the .htacess file can be found at the Apache site. Search the Internet, and you will find hundreds of sites with the information you are seeking. Analysing each site is the hard part.
To start creating an htaccess file, save a file without an extension. The file name must be specified as .htaccess. The server will look for this file when someone visits your site with the modified url, subdomain.domain.com.
In the file add the following lines of code, and becareful;
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} subdomain.domain.com
RewriteCond %{REQUEST_URI} !directory/
RewriteRule ^(.*)$ http://subdomain.domain.com/directory/$1 [L]
The server will not give you any idea of what's wrong. If you make a mistake, the server will just not do anything.
with these instructions you will be off and running. Creating a sub domain is difficult if you have never done anything like it before, but doesn't have to be. Bookmark this page, and forward this to all your friends.
Sub domains lend themselves to an infinite number of possibilities. You can use them for blogs, selling space off your hosting space (until you have too many customers, and have to spend money on a dedicated or static ip), and promoting products and services, without the cost of buying and maintaining another domain. Wow!
Friday, November 18, 2011
Pass Multiple Parameters into a Javascript Function
Learn about the good parts and bad parts of javascript. When java applets failed, javascript quickly became the language of the web by default. This book digs through the good and indentions and blunders to give you a detailed look at the good parts of javascript.
It includes,
- Syntax
- Objects
- Functions
- Inheritance
- Arrays
- Regular expressions
- Methods
- Style
- Beautiful features
It has taken me years, and I finally came across the solution to passing multiple parameters into a javascript function.
Javascript functions have a special property called arguments. They contain an array of input parameters. You can simply use the length property of the array, to find out how many parameters were passed to it.
When setting up your function, do not specify and parameters. For example I have a function called bind, that I use to call generic methods. It uses two parameters, the first parameter specifies the name of the function to be called, and the second parameter specifies the page it is used on.
The function takes no arguments, and is simple specified as bind().
In the function I setup a for loop to loop through the arguments, and determine how many parameters were passed.
for (var i = 0; i < arguments.length; i++) //Loop through total number of arguments passed into the function. { var function_name = arguments[0]; //Get first parameter. //Perform case statements here. }
When you call the function, simply specify the function call as such, bind('para1', 'para2'). That's it. It's really that easy. Then, access each parameter as an array element.
This eliminates the need to store values into hidden fields. Your functions less complicated. There are many times you need to pass more than one parameter into a javascript function. You cannot setup two parameters in the function declaration. The second parameter will always end up being null.
Bookmark this blog for future reference. It will certainly come useful.
Subscribe to:
Posts (Atom)