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

A beginner’s guide to digital marketing in 2020

A beginner’s guide to digital marketing in 2020 It goes without saying that the number of people using the internet is an all-time high in 2020. And with this, people are making more informed decisions about their purchase. Wouldn't you want this statistic to reflect on your sales? Since the beginning, marketing has always been about engaging with your audience in the right place. Today, the right place is where they spend most of their time: on the internet. How? Simple, Digital Marketing. What is Digital Marketing Digital marketing is the advertising of a business, a product, or a service using online channels. It targets a specific set of audience according to a business's needs and demands. In these times, it is on the upswing. You can use multiple channels to create brand awareness and generate more leads. Digital Marketing Channels SEO- Optimize your content according to the dynamic search engine algorithms and attain more visibility in front of your target audience....

Fix for NET Framework 3.5 not installing on Windows 10

I'm a gamer at heart, so you can imagine how annoyed I was when I saw that a Windows 10 error was preventing me from running certain titles. Many modern games require  NET Framework 3.5 in order to run, but... whenever I tried to install it on my Windows 10, I got the " DISM failed. No operation was performed ." error message. Since I'm sure I'm not the only one facing this problem, I've decided to show everyone how to fix it. For those of you who are interested, the Net Framework is a programming infrastructure that Microsoft created to help developers build and deploy products that use .NET technology. Since there are a lot of applications and services that rely on .NET (Dot Net) for their functionality, you can imagine that this kind of error can be quite irritating. Here are a few solutions that you should try: Solution One This is the one that takes the least time, but you need to have the USB stick that contains the Windows 10 installer plugged into your...