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

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 ...

What is a Country? देश भनेकाे के हाे?

Yesterday, on January 13, Nepal's Coat of Arms was updated to add Kalapani and Limpiyadhura as in the new Political map. In this context, we today discuss on what actually 'a country is for it's citizen.' देश भनेकाे के हाे? What is a Country? जनताका लागि देश के हो ? जनताका लागि देश संविधान, कानुन, नागरिकता, सिमाना र झन्डा मात्र हो ? होइन । जनताका लागि देश राजधानी, त्यसबीच ठडिएको दरबार र त्यसको गजुर हो ? होइन । जनताका लागि देश भनेको सरकार हो ? होइन । जनताका लागि देश निर्वाचन क्षेत्र मात्र हो ? हुँदै होइन । त्यसो भए जनताका लागि के हो त देश ? जनताका लागिदेश चार सिमानाभित्रको माटो मात्र होइन । योसँगै जोडिने भावना, प्रेम, ऊर्जा र सपनाहरूको बगैंचा हो । जनताका लागि देश आशा हो । जनताका लागि देश खेतमा झरेको पसिनाको बियाड हो । आन्दोलनहरूमा सडकमा पोखिएको रगत हो । आफ्ना सपनाहरूको कविता हो । जस्तो, एउटा शिशुका लागि आमाको काख । जस्तो, भर्खर हिँड्दै गरेको एउटा बालकका लागि पिताजीको हात । एउटा यात्रीका लागि देश बाटो हो, जसमाथि ऊ आफ्ना पैतालाका डोबहरू छोड्छ र गन्तव्यतिर बढ्छ । देश भनेको ...

Why should you learn Python programming language?

Python is a programming language developed by Guido Van Rossum. It is a very simple programming language so, you can learn Python without facing any issues. You are a beginner at programming can learn python. So, let's see top 7 reasons to learn python: Simple and popular: Python programming language is simple and very popular. Many significant platforms only support Python language. It also ranks top three as per TIOBE Index. Versatile:  It is a versatile language, i.e.; can we used to develop desktop applications, web pages and is considered best for AI and data science. Popularity: Many industries like YouTube, Amazon, Google, Facebook,etc. use this language. So, Python developers are very high in number. Moreover, the users of python are increasing day by day. Portable an extensible: Python course are portable and extensible as a code for Windows even run at Mac, Unix or Linux. Even the codes can be compiled in different languages like C++ or C. Graphical: The Python Computer G...