Skip to main content

Cool javascript tricks and Codes 2017 for websites and Browser

Javascript is very broad and difficult language at all. ( for me may be not for you :p). With javascript we can add interactivity in our web pages and websites. Javascript has creates easiness for the designers and developers. In fact, javascript revolutionized the designing.

There are some little and cool javascript tricks by which you can do a lot of helpful works and add more interactivity to your website. I am not an expert of javascript nor an big blogger but I am the newbie and don't have enough experience. So, that's why sometimes I do a mistake in my writing. If you find any mistake then must inform me.

Auto Select Text Area

Sometimes we need to add some text or you can say a code for the users. So, for the easiness of the users this javascript snippet will help you. By this users can easily auto select the text area which they want to copy.
 <textarea rows="10" cols="50" onclick="this.focus();this.select()" readonly="readonly">
   Your Text Here
</textarea>

Add to Favorite

The first param to AddFavorite is the URL, the second the text to offer up for saving. So this inline JavaScript is reusable in the sense that it will pull those values dynamically from the anchor link itself.

 <a href="http://site.com" onclick="window.external.AddFavorite(this.href,this.innerHTML);">Add Favorite and Go-To-There</a>

Async Sharing Buttons

Many of these services are already running and provide their scripts in an asyc, but this snippet is just combine them in more easy and understandable code.
 (function(doc, script) {
  var js,
      fjs = doc.getElementsByTagName(script)[0],
      frag = doc.createDocumentFragment(),
      add = function(url, id) {
          if (doc.getElementById(id)) {return;}
          js = doc.createElement(script);
          js.src = url;
          id && (js.id = id);
          frag.appendChild( js );
      };
    
    // Google+ button
    add('http://apis.google.com/js/plusone.js');
    // Facebook SDK
    add('//connect.facebook.net/en_US/all.js#xfbml=1&appId=200103733347528', 'facebook-jssdk');
    // Twitter SDK
    add('//platform.twitter.com/widgets.js');
    fjs.parentNode.insertBefore(frag, fjs);
}(document, 'script'));

You will also need an HTML for this snippet to work. 
 <a href="https://twitter.com/share" class="twitter-share-button" data-count="horizontal">Tweet</a>
<div class="g-plusone" data-size="medium" data-count="true"></div>
<div id="fb-root"></div>
<div class="fb-like" data-send="false" data-layout="button_count" data-width="1" data-show-faces="false" data-action="recommend"></div>

Notify the Visitor when Javascript is ON/OFF

This is very helpful snippet to increase your usability. This snippet will tells the user weather the Javascript is on or off.If javascript is on then user gets a welcome message and if javascript is off then the user will be instructed to turn it on.
 <script type="text/javascript">
   document.write("Welcome, you have Javascript on.")
</script>
<noscript>JavaScript is off. Please enable to view full site.</noscript>

Different Stylesheets for Different Days

And here is the last one which I like most. Name your css files accordingly like: Saturday.css, Friday.css, Sunday.css, etc...

NOTE:If JavaScript is disabled in the browser, it will revert back to the default.css file.
 <script type="text/javascript">
<!--
dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
dayNumber = new Date().getDay();
document.writeln('<link rel="stylesheet" type="text/css" href="' + dayNames[dayNumber] + '.css">');
//-->
</script>
<noscript>
<link rel="stylesheet" type="text/css" href="default.css">
</noscript>



Comments

Popular posts from this blog

How to Remove Powered by Blogger – Attribution Widget?

In this article, I will be demonstrating how to remove or hide attribution widget ‘Powered by Blogger’ in footer of blogger blogspot blogs.  Before going to the process,  backup your blogger template , while editing html code if anything goes wrong or template modified design doesn’t work or looks good you can restore from backed up template.  Here I have demonstrated you two methods for removing attribution widget. Some blogger templates may not support method 1 then you need to follow method 2 for successfully removing attribution widget. Method 1: Remove ‘Powered by Blogger’ by unlocking Attribution widget Step 1 : Go to your blog “Template” | click on “Edit HTML”. Step 2 : Here on drop-down “jump to widget” option and select Attribution 1 as shown below Step 3: After selecting Attribution 1 widget you will be able to see this line <b:widget id=’Attribution1′ locked=’true’ title=” type=’Attribution’>  on your blogger template. Step 5: Once done click on...

Top 7 Modules in Python Programming language | 2020

Python is a simple programming language yet of very high level and is very much popular. This days the use of python has gone very high and it is expected to be much higher in the upcoming days in the near future. So, today in this article we will be discussing about some modules in python language which are most to be learnt: NumPy: It helps to do basic mathematical operations and complex math with algebraic formulas, statistical operations,etc. It is a valuable python package and is important for machine learning. Pendulum: It helps to do complex coding involving dates and time and is broad form of datetime module. It also manages the time zone automatically hence, it is a replacement for the datetime module. Python imaging library: It makes easy to write codes that involves to open, read and manipulate or modify images in a variety of formats. The Pillow or PIL imaging library is good for importing, manipulation and exporting images. MoviePy: As pillow is to images, moviePy ...

The four yugas (Era or Epoch) in Hinduism

A yuga is the period-of-time or ages. In Hinduism, the Chatur-yuga (Four-Yuga) are large time periods characterizing and defining humans as well as social development on the earth. There are four different yugas, (Chatur---> Four) and each of them have their own feature in history. Let's see their names: Satya Yuga (सत्य युग) Treta Yuga (त्रेता युग) Dwapara Yuga (द्वापर युग) Kali Yuga(कली युग) Let's learn briefly on them: 1. Satya Yuga: It is also called as Krita yuga, which is the first of the yuga. Satya means truth. It lasted for 17,28,000 years or 4800 Divine years. It is the truth or golden age, where all humans were good and very religious. It was the first and best yuga without crime and all humans were kind and friendly. It is called Krita Yuga as there was one religion and all men were saintly. Humans used to be 33 feet in height and average human lifespan was of 1,00,000 years.   The bull of   Dharma  symbolizes that morality stood on all four legs durin...