20 September 2013

Javascript: open new named tab with window.open

Often we come to a situation where we want to open a url in new tab. At the same time we want to prevent user end up opening many tabs, where we want to open url in same named tab.

1. In modern browsers, window.open will open in a new tab rather than a popup.

2. You can force a browser to use a new window (‘popup’) by specifying options in the 3rd parameter

3. If the window.open call was not part of a user-initiated event, it’ll open in a new window.

4. A “user initiated event” does not have to the same function call – but it must originate in the function invoked by a user click

5. If a user initiated event delegates or defers a function call (in an event listener or delegate not bound to the click event, or by using setTimeout for example), it loses it’s status as “user initiated”

6. Some popup blockers will allow windows opened from user initiated events, but not those opened otherwise.

7. If any popup is blocked, those normally allowed by a blocker (via user initiated events) will sometimes also be blocked.


Forcing a window to open in a new browser instance, instead of a new tab:

window.open('http://www.google.com', '', 'width=1024');

The following would qualify as a user-initiated event, even though it calls another function:

function o(){
  window.open('http://www.google.com');
}
$('button').addEvent('click', o);

The following would not qualify as a user-initiated event, since the setTimeout defers it:

function g(){
  setTimeout(o, 1);
}
function o(){
  window.open(''http://www.google.com');
}
$('button').addEvent('click', g);

Solution example:
http://jsfiddle.net/mn8DN/

30 August 2013

Food Bill or Foot Bill

This govt has systematically broken the spine of the country, here read it for enlightenment:

An economics professor at a local college made a statement that he had never failed a single student before, but had recently failed an entire class. That class had insisted that congress food security bill will worked and that no one would sleep without food .

The professor then said, "OK, we will have an experiment in this class on congress plan". All grades will be averaged and everyone will receive the same grade so no one will fail and no one will receive an A.... (that means tax collected from us will be used for food security bill expense. i.e equally distribution ).

After the first test, the grades were averaged and everyone got a B. The students who studied hard were upset and the students who studied little were happy. As the second test rolled around, the students who studied little had studied even less and the ones who studied hard decided they wanted a free ride too so they studied little.

The second test average was a D! No one was happy. When the 3rd test rolled around, the average was an F.

As the tests proceeded, the scores never increased as bickering, blame and name-calling all resulted in hard feelings and no one would study for the benefit of anyone else.

To their great surprise, ALL FAILED and the professor told them that socialism would also ultimately fail because when the reward is great, the effort to succeed is great, but when government takes all the reward away, no one will try or want to succeed.

These are possibly the 5 best sentences you'll ever read and all applicable to this experiment:

1. You cannot legislate the poor into prosperity by legislating the wealthy out of prosperity.

2. What one person receives without working for, another person must work for without receiving.

3. The government cannot give to anybody anything that the government does not first take from somebody else.

4. You cannot multiply wealth by dividing it!

5. When half of the people get the idea that they do not have to work because the other half is going to take care of them, and when the other half gets the idea that it does no good to work because somebody else is going to get what they work for, that is the beginning of the end of any nation.

Can you think of a reason for not sharing this?

Source: FB

14 June 2013

The Placebo Effect

You may have heard of it before, The Placebo Effect is a phenomenon where patients are given a fake sugar pill and are told it will help them in some way or form. This study has been done many different times for various situations from colds to cancers. Doctors take two groups of people to study, one are given real pills for an ailment, while the others are given sugar pills.

Both groups are told that the pills will help with their ailments. In some patients who take the sugar pills, studies have shown that it works at fighting their sickness just as well if not better than the actual pills.

These studies seem to suggest that the power our mind has to heal ourselves is greater than we have ever thought. Scientists are still baffled as to how this happens.


Source: Anonymous

23 May 2013

How to detect IE10 through JavaScript

I was struggling to detect Internet Explorer 10 through JavaScript. 

Its pretty simple, right?

But its not easy if you change the browser mode or document through developer toolbar or if are running on compatible mode. Most of the solution out there on the internet stopped working for such special cases.

Finally I have found the solution to detect IE10 in all such cases:
- Quirks mode 
- Standards mode 
- Browser mode
- Document mode

<script>

var isIE10 = false;

/*@cc_on
if (/^10/.test(@_jscript_version)) {
isIE10 = true;
}
@*/
alert("Is my running on IE10? " + isIE10);

</script>

19 May 2013

The Cockroach Theory for Self Development



At a restaurant, a cockroach suddenly flew from somewhere and sat on a lady. She started screaming out of fear. With a panic stricken face and trembling voice, she started jumping, with both her hands desperately trying to get rid of the cockroach.

Her reaction was contagious, as everyone in her group also got panicky.

The lady finally managed to push the cockroach away but …it landed on another lady in the group.

Now, it was the turn of the other lady in the group to continue the drama.

The waiter rushed forward to their rescue.
In the relay of throwing, the cockroach next fell upon the waiter.

The waiter stood firm, composed himself and observed the behavior of the cockroach on his shirt.
When he was confident enough, he grabbed it with his fingers and threw it out of the restaurant.

Sipping my coffee and watching the amusement, the antenna of my mind picked up a few thoughts and started wondering, was the cockroach responsible for their histrionic behavior?
If so, then why was the waiter not disturbed? He handled it near to perfection, without any chaos.

It is not the cockroach, but the inability of the ladies to handle the disturbance caused by the cockroach that disturbed the ladies.

I realized that, it is not the shouting of my father or my boss or my wife that disturbs me, but it’s my inability to handle the disturbances caused by their shouting that disturbs me.

It’s not the traffic jams on the road that disturbs me, but my inability to handle the disturbance caused by the traffic jam that disturbs me.

More than the problem, it’s my reaction to the problem that creates chaos in my life.

Lessons learnt from the story:
I understood, I should not react in life. I should always respond.
The women reacted, whereas the waiter responded.

Reactions are always instinctive whereas responses are always well thought of, just and right to save a situation from going out of hands, to avoid cracks in relationship, to avoid taking decisions in anger, anxiety, stress or hurry.

Source: http://www.storydose.com/2013/05/the-cockroach-theory-for-self.html

26 April 2013




22 February 2013

Hate and Potatoes

Once, a Junior School teacher asked her students to bring some potatoes in a plastic bag to school. Each potato will be given a name of the person whom that child hates. Like this, the number of potatoes will be equal to the number of persons they hate.

On a decided day, the children brought their potatoes well addressed. Some had two, some had three and some had even five potatoes.

... The teacher said they have to carry these potatoes with them everywhere they go for a week.

As the days passed the children started to complain about the spoiled smell that started coming from these potatoes. Also some students who had many potatoes complained that it was very heavy to carry them all around. The children got rid of this assignment after a week, when it got over.

The teacher asked, "How did you feel in this one week?"

The children discussed their problems about the smell and weight.

Then the teacher said, "This situation is very similar to what you carry in your heart when you don't like some people. This hatred makes your heart unhealthy and you carry that hatred in your heart everywhere you go. If you can't bear the smell of spoiled potatoes for a week, imagine the impact on your heart of this hatred that you carry throughout your life."

Our heart is a beautiful garden that needs a regular cleaning of unwanted weeds. Forgive those who have not behaved with you as expected and forget the bad things. This also makes room available for storing new love.

Source: #CompanyFridayReading