Show current date using Javascript in web browser(Client side date in web browser)

For client side scripting,

Go through following lines to product date in DD/MM/YYYY format:

var objToday = new Date();
var dd = objToday.getDate();
var mm = objToday.getMonth() + 1;  //January is 0
var yyyy = objToday.getFullYear();

if (dd < 10) { dd = ‘0’ + dd }
if (mm < 10) { mm = ‘0’ + mm }

var strToday = dd + ‘/’ + mm + ‘/’ + yyyy;

alert(strToday);       // will show like ’17/07/2013′

Advertisements

Change page meta title by using javascript

I just seen one site was using this feature, and was changing its meta title/page title displaying in browser window title bar.

So sharing following useful, one line code snippet giving you idea about it.

<script type=”text/javascript”>

document.getElementsByTagName(‘title’)[0].innerHTML = “your dynamic title goes here…”;

</script>

Such small dynamism makes our website looks more interactive.

One thing to remember about this is that, changing meta title will not help SEO wise, as its changing with java script. Web crawler will have default page title in his record.

Web development small tips

Single quote in java script, may result in error

In Javascript,when using or concatenating string, use it with double quotes.
Or it may generate error.

Recommanded:
var str="Some String" + document.getElementById("txtName").value;

Should be avoid:
var str='Some String' + document.getElementById("txtName").value;


To overcome Date format related error, in .Net, with CompareValidator validation control
You can, specify culture in web config file.


Put Share Button on your website with ADD THIS

Go to http://www.addthis.com site, and it will ask you button layout you want to Choose.
And that site will display code snippet, which will contain one SCRIPT tag and HTML lines.

So you have to add script line in your page and put ‘html’ tags at place where you want to display share icons.


To set content in tinyMCE editor box by using javascript
var editorInstance = tinyMCE.getInstanceById("ctl00_cpMain_txtCampaignDesc"); //specify clientid of textarea field
editorInstance.getBody().innerHTML = "This is dynamic text set by javascript.";