Wednesday 1 June 2016

How to add prefix of http and https in your url automatically when you enter text like (google.com) in your textbox.

You can add http or https in your url very easily in your textbox by using jquery. This is done by using the jquery blur method you can achieve this result easily.

Below is the jquery code:-

$(document).ready(function () {
 $(selector).blur(function () {
            unSavedChangesInPopup = true;
            var input = $(this);
            var val = input.val();
            if (val && !val.match(/^http([s]?):\/\/.*/)) {
                switch (val) {
                    case 'http':
                        input.val(val + '://www.');
                        break;
                    case 'http:':
                        input.val(val + '//www.');
                        break;
                    case 'http:/':
                        input.val(val + '/www.');
                        break;
                    case 'https':
                        input.val(val + '://www.');
                        break;
                    case 'https:':
                        input.val(val + '//www.');
                        break;
                    case 'https:/':
                        input.val(val + '/www.');
                        break;
                    case 'www':
                        input.val(val + '/www.');
                        input.val('http://' + val + '.');
                        break;
                    default:
                        input.val('http://www.' + val);
                        break;

                }
                
            }
        });
 });

1 comment:

  1. TiGEN - Stainless Steel - Titanium Darts
    Stainless steel, Titanium Darts & titanium bolt More. tungsten titanium Made titanium dab nail in United States titan metal with where is titanium found the highest quality Stainless Steel. Stainless steel in stainless steel. The edge of the

    ReplyDelete