Validate Target Blank With XHTML Strict

Using target=”_blank” in links while writing HTML is very common. But XHTML Strict validator does not support target attribute in links. So for validating a page with XHTML Strict and still use target=”_blank” we need to do the following with the help of JavaScript –

Normal HTML

 

Validated HTML + JavaScript

 

 
Posted in HTML, Javascript | Tagged , , , , , | Leave a comment
 

How To Get JavaScript Code XHTML 1.0 Strict Validated

Under certain circumstances we are left with no other choice but to write our JavaScript code in the XHTML file itself. And after that when we try to validate our site with the XHTML validator we get errors for the JS code. Lets see how we can get these validated properly.

Problem generally arises with the “<” or “>” symbols used in loops or conditions or any HTML used within the JavaScript (for example setting any HTML with innerHTML).

To validate these JavaScript codes wrap them with CDATA.

 

Now the JavaScript codes in the HTML document will pass the XHTML Strict validation.

Posted in HTML, Javascript | Tagged , , , | Leave a comment
 

Using Media Queries To Write CSS

For a long time we have been able to specify styles for different media types using CSS ; print and screen being the most recognizable. With CSS3 these media types have been extended to allow additional expressions, also known as media queries, which give us greater control on when specific styles should be applied.
Media queries enable us to target specific features (screen width, orientation and resolution) within CSS itself. We can use them in two ways:
1) inline in a CSS style sheet
OR
2) as the “media” attribute in the link tag, which loads an external style sheet.

Let’s explain with a few examples.

Example – 1

/* Portrait */
@media screen and (max-width: 800px) {
    /*required css*/
}
/* Landscape */
@media screen and (min-width: 1224px) {
    /*required css*/
}

Example – 2

/* Portrait */
@media screen and (orientation:portrait) {
    /* Portrait styles */
}
/* Landscape */
@media screen and (orientation:landscape) {
    /* Landscape styles */
}

We can also write the same media query using the other method, which points to an external style sheet (not recommended):



The last example process is not recommended because it creates an additional HTTP request (bad for performance). Also, in the case of screen orientation, the separate CSS style sheet is not downloaded when the screen is rotated.

Posted in CSS, HTML | Tagged , | Leave a comment
 

How To Detect Mobile Devices With JavaScript

Sometimes we may need to know whether or not we’re dealing with a mobile device. Using JavaScript we can get it by parsing the UserAgent string.

For example if you are using Apple iPad the userAgent will return the value -
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10.

Lets see how we can get the userAgent and use it to determine the device.

var uagent = navigator.userAgent.toLowerCase(); 
var device = '';
if (uagent.search("iphone") > -1)
       device = 'iphone';
else if (uagent.search("ipod") > -1)
       device = 'ipod';
else if (uagent.search("tablet") > -1)
       device = 'tablet';
else if (uagent.search("ipad") > -1)
       device = 'ipad';
else if (uagent.search("android") > -1)
       device = 'android';
Posted in Browser, Javascript | Tagged , | Leave a comment
 

How To Add Multiple Images For Products In Zen Cart

Zen Cart does not allow uploading of multiple images for the same product directly from the admin interface. However it is possible with the help of manually uploading the images via FTP. Let’s see how to do it in details.

1. Create a product and upload the first image for it from the Zen Cart admin. Lets assume name of the image is product_image.jpg and it is uploaded in the “images” folder.

2. Rename the extra images of the same product as product_image_1.jpg , product_image_2.jpg . product_image_3.jpg …. product_image_x.jpg

3. Upload the extra images in the ‘images’ folder (same folder where the main image was upload via the Zen Cart admin) using the FTP.

That’s it. You will be able to see the extra images in the product details page now.

Njoy :D

Posted in PHP, Zen Cart | Tagged , , | 1 Comment