Tag Archives: Tips & Tricks

How to set Cookies to share across all subdomains using JavaScript

Browser Cookies, is a very handy feature that enables us as a web developer to do so many interactive programming. Recently since HTML5 raised up, its Web Storage is replacing this feature. But there is one area where Web Storage fails to achieve the result – subdomain access. There we have to again jump back for old school document.cookie method.

In this very quick tutorial, lets discuss how we can setup browser cookies that can be accessed from all subdomains and root domain. But proceeding further requires basic knowledge of cookies, and if you need to learn, Tutorial Point has good article on JavaScript Cookies.


  1. Prepare the cookie name/value
  2. Get the top level domain and assign as .domain.com
  3. Set the path to root path=/
  4. Set Expires (optional)

Lets set up a example cookie. Example take as ‘Last time report generated’ to showup across subdomains.

var LastReportGenerated="Jul 11 2013",
baseDomain = '.cssjunction.com',
expireAfter = new Date();

//setting up  cookie expire date after a week
expireAfter.setDate(expireAfter.getDate() + 7);

//now setup cookie
document.cookie="Report={'ReportName':'MainReport', 'lastGenerated':" + LastReportGenerated + "}; domain=" + baseDomain + "; expires=" + expireAfter + "; path=/";

Major thing to take care here is:

Your domain must be in format of “.domain.com” – dot and root domain and your path=/ always. If you don’t setup your path=/, auto path will be saved as from where the cookies is being saved hence it wont be accessible across any subdomain.

You can try copy paste code above in the Console, and see the result in Resource Panel. If you happen to successfully run the script above, you will get a preview:

JavaScript Cookie

Now that ‘Report’ cookie should be available across all subdomains like = main.cssjunction.com, tuts.cssjunction.com etc.

Detect Landscape/Portrait Mode using JavaScript

Detecting device mode (landscape or portrait) using CSS3 is now very much easy and it is state of art. But it wont work on certain situations like I had. I failed to make @media queries detect device oriantaion on Iphone. So I came to write a JavaScript fix to get work done.

Check my oriantation test using CSS3 @media queries here. The demo page should show text ‘Portrait’ on portrait mode and ‘Landscape’ on respective mode. But it does not. You might want to try with you own device. Some of my friends said it is working. Check out the discussions on Forrst.

I Googled for the solutions, but I must say I couldn’t find any reliable one :(. If you prefer to use CSS3 media queries, check out the post on Stuff & Nonsense. And here it goes my JavaScript function that will detect the landscape/portrait mode.

First, lets create a function called ‘checkOrientation‘ so that we can evoke it by just a name instead of repeating whole lines.

Inside this function we will check the device oriantion degree which we are going to take from window.oriantation method. If we get the degree 0 its the mode portrait else its landscape.  Since we will be using window. orientation method, this function will only work in handheld devices. So here it goes our function:

function checkOrientation(){
      var currMode = "";


           case 0:
           currMode = "portrait";

           case -90:
           currMode = "landscape";

           case 90:
           currMode = "landscape";

           case 180:
           currMode = "landscape";
     document.getElementsByTagName("body")[0].setAttribute("class", currMode);

I have used switch statement to set the currMode variable, which we are going to use as class on required html elements. I set that class on body.

Now its time to call the function, you can call it directly or on window.load method. I think window.load method is better and safe. So lets call it:

window.load = function() {

When our page is ready, check the class of body element. We are done. But wait what if we change the oriantaion now? Yes, we need to update the class on oriantation change.

For this, we have window.onorientationchange method, which is also available on devices only. We will recall our function inside this method:

window.onorientationchange = function(){

Thats it. Now we are completely done. Check-out the Landscape/Portrait Mode detection demo.

7 Ways to Code Faster HTML CSS

7 Ways to Code Faster HTML and CSS

Are you a fast coder? Yes? If then how fast you can code? Being a fast typist isn’t about coding faster. Faster coding is about getting more things done with less effort. Here comes the role of productivity tools.

Listed below are some very useful productivity tools – for Frong End Developers. The tools below will help you code must faster and saves a lot of time. After all we are not a typist :), so why don’t we use these tools:



Zen Coding is an editor plugin for high-speed HTML, XML, XSL (or any other structured code format) coding and editing. The core of this plugin is a powerful abbreviation engine which allows you to expand expressions—similar to CSS selectors—into HTML code.

Best learn resource: http://coding.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/

2.) Halm

Haml is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ASP, and ERB, the templating language used in most Ruby on Rails applications.

Best learn resource: http://haml-lang.com/tutorial.html

3.) Sparkup

You can write HTML in a CSS-like syntax, and have Sparkup handle the expansion to full HTML code. It is meant to help you write long HTML blocks in your text editor by letting you type less characters than needed.

Best learn resource: http://thechangelog.com/post/1421721495/sparkup-a-parser-for-a-condensed-html-format


4.) LESS

The dynamic stylesheet language. LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.

Best learn resource: http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/get-into-less-the-programmable-stylesheet-language/

5.) SASS

Sass is a meta-language on top of CSS that’s used to describe the style of a document cleanly and structurally, with more power than flat CSS allows.

Best learn resource: http://net.tutsplus.com/tutorials/other/mastering-sass-lesson-1/

6.) Prefixr

CSS Prefixr is a CSS pre-processor tool, that generates the cross browser css from given codes. Forget about writing multiple browser prefixes and start using Prefixr.

7.) SpriteCow

Sprite Cow helps you get the background-position, width and height of sprites within a spritesheet as a nice bit of copyable css.

All of the above tools are my daily usage tools. Once you get the rid of using these tools – you will thank me for listing.

How to remove black border around input buttons in IE 7?

Here I am sharing a bullet proof working solution to remove ugly black border around IE 7 input buttons.


The problem is there when a submit button is inside the form element. Click outside the form, form focus is gone,thus black border is gone. But form is focused when page loads so the problem exists there.

IE7 Black border around input buttons

Not working solution

Every one suggest to add outline:none to fix this problem, since outline property is not supported by IE7, I say that this is a not working solution.

Bullet proof Solution

Just one property is required to get rid of this black border. Open you reset css file and add the these lines:


Why in reset css file?

Because the problem is for all buttons in IE 7, since adding this fix in reset.css will fix our problem in entire site.

That’s it. All black border is gone now. The fix is tried/tested against IE 7.


Fixed IE7 Black border around input buttons

Better if you put this fix in IE7-CSS file.

Similar IE 7 Quick Trick

How that sound to you? Isn’t it helpful :).

Resources to write better resumes and cover letters.

Write Better Resumes

Firstly a good Cover letter and secondly a better resume – the main weapons for all candidates who is seeking for a good job. This is where you’ve got a change to prove yourself that you’re the best fit for required position among others. It makes sense, having a good resume, but having a better resumes makes more sense and helps you better stand out from the crowd.

How are you doing on creating a effective resume? Here I have listed some of the best & proven to work resources that is definitely going to help you get most of it. Write a better resume, you got to read these guide lines.

Oxford Career Guide

Visit page

“A CV (curriculum vitae, or résumé in the US) is a summary of your academic, extra-curricular and work experience. It should be a brief document that illustrates you skills, achievements and interests.”

Google Student Guidelines for preparting resumes

Visit page

“To make it easier for us to determine where you might best fit within our organization, you can take a few simple steps to help us understand your qualifications.”

Target Jobs Career Advice

“Graduate CVs and job applications: they can take as much planning and preparation as an essay or project write up. Here we cover the basics of how to tackle online applications, structure a graduate CV and put together a covering letter.”

Harvard Business School’s Career Development

Visit page

“The resume is an opportunity to market yourself to a prospective employer. It should be succinct, target an employer’s needs, and distinguish you from your competitors.”

FreelanceSwitch Resume Basics

Visit page

“Many freelancers may think that a resume is a thing of the past—something only used to get a corporate job. So if you’re done climbing the corporate ladder, why would you need a resume?”

Monster.com’s Career advice

Visit page

“In a competitive job market, we have to do everything we can to make our resumes more attractive to hiring managers. This can be difficult for older workers, who fear that even if there’s no bias (subconscious or conscious) against job seekers on the mature side of 40, a resume may make them look overqualified for the positions they want.  ”

businessballs.com’s -> how to write a cv

Visit page

“While the basic rules of a good CV remain constant, the world of work and business changes quickly. This especially impacts on how managers and graduates can best show themselves to be outstanding candidates.”

oDesk blog

Visit page

“A wise freelance writer will not only be computer literate, but will also have a few other tech tricks up his/her sleeve. If you aren’t bringing in the freelance writing gigs you want, it may be time to sign up for a class or teach yourself one of the following writer-friendly tech skills.”

Smashing Magazines’s tips

Visit page

“Ah, the dreaded cover letter. Boring to write, difficult to get right, and you’re usually preoccupied by other things (such as the portfolio and resume, which are also really important).  Unfortunately, your cover letter is a company’s first exposure to you, and it determines whether your application is trashed or fast-tracked to the company’s to-hire list.”

Till here, you came so far, write a better resume & get a better dream job – best of luck.