Load Different JavaScript for Different Browsers

Hi friends, in this article we are going to learn how we can load different JavaScript for different browsers. Few days ago I was trying to implement back button in one of my html page. The page on which I was trying to implement Back button was loading from one of the auto redirected page.

So this back button was working on Chrome browser but not on Internet Explorer. Chrome is enough intelligent browser and it can detect that the page is from one redirected page. So when we click on back button it will land you to 2 pages back. But Internet Explorer cant have this intelligence.

When I was trying to click on Back button in Internet Explorer, it was loading previous page. As previous page was having auto redirect code so it again goes to same page which was having Back button. So using Back button in Internet Explorer was producing never ending loop. So I thought to implement one trick which will load 2 page back button in IE. This can be implemented by loading Browser specific JavaScript. Using this method we can load different JavaScript for different browsers.

Browser Specific JavaScript

Here we are using Back button which will call goBack() onclick event.

 <input type="button" onclick="goBack()" value="BACK" />  

We all know that we use window.history.go(-1); for loading previous page. But we need window.history.go(-2); to load in Internet Explorer. We can use following code which will load these actions depending on which browsers you are using.

 <script>  
      function goBack() {  
       // Internet Explorer 6-11  
       var isIE = /*@cc_on!@*/false || !!document.documentMode;  
       if(isIE)  
       {  
         window.history.go(-2);  
       }  
       else  
       {  
         window.history.go(-1);  
       }  
      }  
 </script>  

This script can be used to load window.history.go(-2); for IE browser and window.history.go(-1); for browsers other than IE.

I hope you liked this article. If you have any queries feel free to ask in comment section. Please like our facebook page and subscribe to our news letter for future updates.

How To Allow Visitors To Upload Files To Your Website

In this tutorial we are going to learn about how to allow visitors to upload their files on your website. Let me clear you one thing that those uploaded files will be saved in your Dropbox folder. Many times website or blog owners want to allow visitors to upload their files on their website.

The possible solution might be Email. But it becomes very difficult for website owner as well as visitor to upload and download files easily. Another way is to make a shared folder. But it will allow visitor both read and write. So here is one simple method which will embed an uploader form into your site so that there is no need of any registration or other things for the visitors. It will be very easy to upload files to your visitor. (See example form here)

If you too want to embed an upload button on your website then you are at right place. You are reading this article that means you have little bit knowledge about pasting a code (html, JavaScript) in your website.

So we are using a popular web form builder called Jotform.com. Using this simple web form builder you can create your customized web form without writing a single line of code.

Allow Visitors to Upload Files on your Website

Following are the steps to embed an upload file button (i.e. file uploader) form into your website.

As we are using our Dropbox account to store the uploaded files from the visitors, you should first sign in to your Dropbox account. (If you do not have account on Dropbox, create it here).

Then go to http://www.jotform.com/dropbox/ and click on “Create a Dropbox Form”

Jotform-Dropbox integration

It will ask you to give API access to your Dropbox in order to deliver your files.

Once you complete these steps click on “Launch Form Builder”. Following window will appear.

Jotform form builder

Click on “Source Code” you will get a Javascript code. Now you can use this code wherever you want to allow visitors to upload their files into your Dropbox folder. If you don’t know how to use this Javascript code into your website read following instructions.

In this example I am going to use a blogger platform.

Go to your Blogger dashboard. Click on layout > add a Gadget a pop up window will appear as follws:

Add a Gadget Pop up

Select HTML/JavaScript and paste a Javascript Code that we have copied from jotform.

See example form: Click here

If you like this article don’t forgot to share and like our Facebook page!