17 Jul
2010

Setting up a Local Web Server

When creating and/or testing web applications, actually running the script can be annoying and tiring. This is because you need to have access to a usable server appliance and be able to connect to it through FTP. Also, if you are planning to edit the files you have to keep uploading and downloading the corresponding files.

A simple way to solve this issue is to transform your actual computer into a web server (for your use only). This, although possible, would not be accessible to other users. You can do this by using a program called XAMPP (Cross Platform, Apache, Mysql, PHP, Perl). It installs the designated software and runtimes that allow it to run on your computer (eg. Apache).

Pros:

  • No need to keep transferring files
  • Unlimited resources (e.g bandwidth)
  • Free

Cons:

  • A lot of your computer resources may be throttled (e.g CPU and RAM)
3 Jul
2010

Cross-Browser Website Viewing

With today’s technologies, almost anyone can create a website. Only a few will succeed in the business world. This is because of many factors. Have you ever been to a website and it doesn’t look right? Graphics many appear in incorrect places and navigation menus may not work. This happens because the website developer hasn’t took into account that different web browsers on different operating systems render pages in separate ways. Safari and Google Chrome use the Webkit rendering engine and that is why pages in those two browsers should almost appear the exact same. However, others don’t, such as:

. Internet Explorer

. Mozilla Firefox

. Opera

Browsershots is a web service where you can see your website in 80 different browsers on 4 different operating systems. It is easy-to-use and functional but does have a few drawbacks. However, these limitations are to be expected because of bandwidth and cost related issues.

How does it work?
1. User inputs URL and selects browsers

2. Request is sent from website to the computers

3. Screenshots are taken and sent back to the website

Pros:

. Easy-to-use

. Able to check website in most internet browsers

. Free

. You are able to change web browser preferences, eg. screen size, Javascript, Flash, Java

Cons:

. Request deleted after 30 minutes

. Limited to 80 web browsers

. Only one website a day

. Some screen shots are taken before the page has loaded

In conclusion, Browsershots is a great utility and it is recommended that you use it when creating your websites.

1 Jul
2010

Ajax Search Suggestions Tutorial

Ajax is a method of using Javascript and XML to grab data from an external source or resource without having to refresh or initiate a new connection. This allows you to continuously interact with a server without the need to refresh the page. Here we are going to build a script that displays a list of suggestions to search when data is entered into an input field. For this, it would be helpful if you have at least a basic understanding of Javascript, HTML and PHP.

First, create 3 files. The names are listed below:

. ajax_framework.js (to create the Ajax connection and grab the output data)

. index.php (the location where the input field and suggestions will appear)

. suggest.php (to generate the suggestions)

Now we must add or content to the files. We will start with the main file, index.php.

Index.php

<!DOCTYPE html>

<html>

<head>

<script language=”javascript” src=”ajax_framework.js”></script>

</head>

<body>

<input type=”text” id=”q” onKeyUp=”javascript:suggest();” onKeyDown=”javascript:suggest();”>

<div id=”suggestions” style=”display:none;”>

</div>

</body>

</html>

Ajax_framework.js

function createObject() {

var request_type;

var browser = navigator.appName;

if(browser == “Microsoft Internet Explorer”){

request_type = new ActiveXObject(“Microsoft.XMLHTTP”);

}else{

request_type = new XMLHttpRequest();

}

return request_type;

}

var http = createObject();

function suggest() {

q = document.getElementById(‘q’).value;

nocache = Math.random();

http.open(‘get’, ‘suggest.php?q=’+q+’&nocache = ‘+nocache);

http.onreadystatechange = suggestReply;

http.send(null);

}

function suggestReply() {

if(http.readyState == 4){

var response = http.responseText;

s = document.getElementById(‘suggestions’);

if(response!=”"){

s.innerHTML=response;

s.style.display = “block”;

} else {

s.style.display = “none”;

}

}}

Suggest.php

<?php

$connect = mysql_connect(“localhost”, “DB_USERNAME”, “DB_PASSWORD”);

mysql_select_db(“DB_NAME”);

$searchq  = strip_tags($_GET['q']);

if(strlen($searchq)>0){

$sql = ’SELECT * FROM  TABLE_NAME WHERE  COLUMN_NAME LIKE “‘.$searchq.’%” LIMIT 0,6′;

$getsql = mysql_query($sql);

while ($row = mysql_fetch_array($sql)) {

$word = $row['word'];

?>

<div onclick=”q.value=’<?php echo $word; ?>’;”>

<?php echo $word; ?>

</div>

<?php

}

}

?>

// Note: You must change the MySql connect details as well as adapt it to your database and table structure.

If you have any problems, please contact me using the contact page.

22 Jun
2010

Building a Simple Chrome Extension

Web Browser extensions are the best way to increase a browser’s functionality. Millions of people use browser extensions, so building them is a great way to become popular. Here we are going to build a simple, Hello World Google Chrome extension. The extension will display a pop-up dialog when clicked which will show the text “Hello World”.
Chrome extensions are easy to build and can be quickly added to Google’s database thanks to their automatic uploader. Lets get started with the basics.
All Google Chrome extensions require at least two components. Most importantly is a manifest file which stores the extension’s information and tells the browser what to do when a particular action is called. Secondly, we will need an image for the extension’s icon. In this extension, we will also need an HTML file that displays the user interface.

Introduction
Before we can make the extension work, we must create a directory that will house our files. Within this directory you are going to need to create some files. These are:
. manifest.json
. popup.html
. icon.png
Make sure you create all of these files before you move on.

Manifest
Open the manifest.json file in your favourite text editor and copy the code below into it:

{
“name”: “Hello World”,
“version”: “1.0″,
“description”: “An application that displays the text Hello World when clicked.”,
“browser_action”: {
“default_icon”: “icon.png”,
“popup”: “popup.html”
}
}

Before you can carry on, it is recommended that you alter the settings above.
Note: Only change the value and not the property name.

Icon
Your icon should have a transparent background and be a .png image file. The dimensions can be changed but it is recommended to stay between 20 x 20 and 36 x 36 pixels.

Popup.html
Assuming you have a basic grasp on CSS, HTML and maybe Javascript. You can change the contents of this file to whatever you like. It is basically like a mini web browser within the small pop-up window. Copy the code below into the file and then save it.

<style type=”text/css”>

body {

width:350px;

height:70px;

font-size:60px;

color:#000;

font-family:Arial;

text-align:center;

}

</style>

Hello World

Make sure you have the text “Hello World” as well.

Testing it Out!
Evidently you will need Google Chrome installed to test it out. To test it out, follow the instructions below:

1. Click the wrench icon in the top right of the Google Chrome window.

2. Now click the Extensions option in the menu.

3. When the page has appeared, click the Developer Mode link towards the top right, a new menu should now appear.

4. Click the first button with text Load unpacked extension.

5. Now choose the directory in which all of your new files are located in.

6. Simply click the icon in your Google Chrome navigation bar and see if it works. If it does, the text “Hello World” will appear in large black characters. If it doesn’t work, re-read this article and check your code.

If you have any problems, comment below and I will try my best. Hope this helps you get started!

21 Jun
2010

Project – SR_DiggIt

Name: SR_DiggIt

Release: 1.0

Description:
This plugin allows you to add a simple Digg button to your website. When clicked it will allow the user to post the current page URL to the social news website Digg.

Instructions:

1. Copy the code below:

<!– SR_DiggIt Start –><script type=”text/javascript”>function submitdigg() {var url = window.location;var diggurl = ‘http://digg.com/submit?url=’+url;window.location = diggurl;}function togglebutton() {var button = document.getElementById(‘digglink’);if(button.src==’http://www.samruston.co.uk/projects/SR_DiggIt/images/button.png’){button.src = “http://www.samruston.co.uk/projects/SR_DiggIt/images/button_hover.png”;} else {button.src = “http://www.samruston.co.uk/projects/SR_DiggIt/images/button.png”;}}</script><style type=”text/css”>#digglink {cursor:pointer;}
#diggcontainer {border:1px #666 solid;background-color:#CFCFCF; font-family:Arial; font-size:10px; -moz-border-radius:6px; -webkit-border-radius:6px; width:125px;padding:4px;text-align:center;}#sponsorlink {color:#333; text-decoration:none; font-family:Arial; font-size:10px;}</style><div id=”diggcontainer”><img src=”http://www.samruston.co.uk/projects/SR_DiggIt/images/button.png” onmouseover=”togglebutton();” onmouseout=”togglebutton();” id=”digglink”  alt=”Digg It!” title=”Digg It!” onclick=”submitdigg();”><br>Created By <a href=”http://www.samruston.co.uk” id=”sponsorlink”>Sam Ruston</a></div><!– SR_DiggIt End –>

2. Insert it into the desired part of your website.

3. Test it out!

20 Jun
2010

The jQuery Basics


jQuery is an advanced, easy-to-use Javascript library that allows you to create beautiful and complex animations on your websites and web applications. It is easy to get started with it and works in almost any browser. Some components do not work in most Internet Explorer versions.

To get started, you must download and upload the jQuery script. It is free and can be found here:
jQuery Download.

Showing/Hiding:

Showing and hiding objects on a web page is probably the easiest method of using jQuery. It only requires the ID or CSS class of an object, the way in which you want it to animate and the time parameter.
First, we will try to make a DIV minimize.
Demo:

Click Here.

Code:

onclick=”$(this).slideUp(500);”

Lets split this snippet of code up. First we can remove the onClick event handler that is common in most Javascript scripts. The onClick function just starts the function when the element is clicked. Next, we look at the “$”. The dollar sign is the symbol used to signify that you want to execute jQuery. So, whenever you are writing jQuery, make sure you add the dollar signs before the actual animation. Now, we must define the element we want it to affect. Here we are using the word, “this”. “This” declares that we want to affect the object where the code is placed. In this case, it is the grey DIV. Next, we must place a period to start executing the type of jQuery animation we want to include.

Here are the most common methods:

. slideUp (Hides the element in a sliding motion)
. slideDown (Shows the element in a sliding motion)
. hide (Shrinks and fades the element to 0)
. show (Increases the size and opacity back to the original properties)
. animate (Declares an animation which is designated later on)

Finally, we must add our time parameter. You can either use a word or number of milliseconds. Here we are using the number 500, this means 500 milliseconds (half a second). This is the duration of animation. Basically, it will take half a second for the DIV to become hidden. Another method is to use a word. You can use ‘slow’ or ‘fast’ depending on your preferences. If you use this method, make sure you add the apostrophe symbols on either side of the word. However, this method is not recommended as it is not customizable compared to the time parameter in milliseconds.

Animation

Animation is a method of editing the properties of an element such as:

. Width
. Height
. Opacity
. Positioning

We will start with the creation of the DIV.

<div></div>
Now we will give it a background colour and some dimensions.
<div style=”width:250px; height:200px; background-color:#CCC;”></div>
Next, we will add the onClick Javascript event and create a simple jQuery structure.
<div style=”width:250px; height:200px; background-color:#CCC;” onclick=”$(this).”></div>
Now we must define that we want to manually animate the element and choose which animation we would like to use.
<div style=”width:250px; height:200px; background-color:#CCC;” onclick=”$(this).animate({‘width’ : ’300px’} ,500);”></div>
The code snippet above will generate a grey DIV with the width of 250px. When it is clicked, the width of the DIV will animate to 400px over the time period of half a second.
Demo:
Click Here
Make sure you memorize the methods and have fun with smooth animation if jQuery.
20 Jun
2010

Welcome To My Blog!

Hello and welcome to my new blog. Here you will be able to find tutorials about technology and website building. Also, you will be able to download and view my current online projects such as:
. Web Applications

Search

Advertisement

Recent Posts

Blogroll

Advertisement

Digg

Digg It!
Created By Sam Ruston

Tags

ajax animation basic basics browser building Button Chrome coding cross Digg Digging down drop Embed extension fade fading Google Hello html internet javascript jquery movement mysql new php programming projects review Ruston Sam script search shots simple SR_DiggIt Submit suggest suggestions web welcome Widget World