Posts Tagged ‘Javascript’

For a animated way back to the top

$(document).ready(function() { $(‘a[href*=#]’).click(function() { if (location.pathname.replace(/^\//, ”) == this.pathname.replace(/^\//, ”) && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $(‘[name=’ + this.hash.slice(1) + ‘]’); if ($target.length) { var targetOffset = $target.offset().top; $(‘html,body’).animate({ scrollTop: targetOffset }, 900); return false; } } }); // how to use // place this where…

Read More

Center an element in the center of your screen.

$(document).ready(function() { jQuery.fn.center = function() { this.css(“position”, “absolute”); this.css(“top”, ($(window).height() – this.height()) / 2 + $(window).scrollTop() + “px”); this.css(“left”, ($(window).width() – this.width()) / 2 + $(window).scrollLeft() + “px”); return this; } $(“#id”).center(); });

Read More

What I can determine about you from your browser alone

Our browsers send off quite a bit of information about us now. Using the fingerprintJS library I was able to abstract this information. Browser Used: language: color_depth: pixel_ratio: resolution: available_resolution: timezone_offset: session_storage: local_storage: indexed_db: cpu_class: navigator_platform: do_not_track: regular_plugins: canvas: canvas winding:yes~canvas webgl: adblock: has_lied_languages: has_lied_resolution: has_lied_os: has_lied_browser: touch_support js_fonts

Read More

Focus OnLoad

You can put the user’s cursor inside a text box (calling the text box’ focus) as soon as the page is loaded. This helps ensure that visitors do not ‘overlook’ an important form item on your site. It only uses one line of code! This part goes into your body tag: <BODY OnLoad=”document.nameform.user.focus();”> Then you…

Read More

Back Button, Add to Favorites, Break out of frames

Just like your browser’s back button, the following script allows the user to press a button to returns the user to the previous page. Paste the following code where you want the button to appear on your page: <FORM> <INPUT TYPE=”Button” VALUE=”Previous Page” onClick=”history.go(-1)”> </FORM> If you would rather use a link, paste the following…

Read More

Close Window

A close window function is useful when you use a pop-up window on your page, as it allows the visitor to easily close the window. You can do it several ways: To use a button, paste the following where you want the button to appear: <form> <input type=button value=”Close Window” onClick=”javascript:window.close();”> </form> For a text…

Read More

Copy selected text

Often you may have some information on your page that your visitors might want to copy. You can make it easier for them by providing a mechanism that allows them to simply click a button to do so. First you need to paste this code into the head of your web page: <SCRIPT LANGUAGE=”JavaScript”> function…

Read More

Obtaining reffering Page in javascript

Determining the reffering page is a awesome information for SEO analytic, rather then posting back to the server. Well display it, You can do so using a few lines of code, as shown here. Place the code where you want the IP address to appear: <SCRIPT LANGUAGE=”JavaScript”> var ip = ‘<!–#echo var=”REMOTE_ADDR”–>’; document.write(“Your IP address…

Read More

Obtain IP address

Sometimes showing viewers there own IP address can deter malicious intent, <SCRIPT LANGUAGE=”JavaScript”> var ip = ‘<!–#echo var=”REMOTE_ADDR”–>’; document.write(“Your IP address is” + ip); </script>  

Read More

Javascript Calender Display

This is a plain and simple monthly calendar. It’s formatted with styles sheets so the appearance can easily be changed. In the head of your document, add the following style sheet and JavaScript code: <style type=”text/css”> span.label {color:black;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 13px Arial} span.c1 {cursor:hand;color:black;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 13px Arial} span.c2 {cursor:hand;color:red;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 13px Arial} span.c3 {cursor:hand;color:#b0b0b0;width:30;height:16;text-align:center;margin-top:0;background:#ffF;font:bold 12px Arial} </style> <script type=”text/javascript”>…

Read More

Javascript Date Display

You can use this snippet to display the current date in this format: Friday, June 11, 2010. Just paste the following code where you want the date to show up on your page: <SCRIPT LANGUAGE=”JavaScript”> var now = new Date(); var days = new Array(‘Sunday’,’Monday’,’Tuesday’,’Wednesday’,’Thursday’,’Friday’,’Saturday’); var months = new Array(‘January’,’February’,’March’,’April’,’May’,’June’,’July’,’August’,’September’,’October’,’November’,’December’); var date = ((now.getDate()<10) ?…

Read More