Protect your content
2011-07-04
Although there is no way to completely protect your content, atleast you can do something to make it harder. This restrictions are sometimes mandatory for different websites, so here are the tips how you can protect your content using javascript. So it is possible to: disbale right click of the mouse and...Get scroll position of webpage - crossbrowser
2011-05-20
Here is a function to get scroll position of current webpage: <script type='text/javascript'> //get scroll position var get_scroll = function(){ var x = 0, y = 0; if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant y = window.pageYOffset; x = window.pageXOffset; } else if(...Prevent default event behavior - crossbrowser
2011-05-20
With almost each javascript event there is a default behavior that is followed after event's been fired. For example, if you click on a link, you can do stuff provided in onclick event, and then you'll be redirected to provided URL. Not all event behavior can be prevented, usually it can be determined using event.cancelable...Get relative cursor positions
2011-04-13
Every browser support clientX and clientY mouse event properties to get cursor position relative to screen you see. If you'd like to get cursor position relative to whole page (counting scrolling position), it could be done using this function: function get_page_coord(e) { //checking if pageY and pageX is already available if...Javascript events - crossbrowser
2011-02-27
Here's a two useful functions to manipulate events in javascript. First one allows you to add new event. And second one will return you element, which fired event. //add event var add_event = function(element, type, listener){ if(element.addEventListener) { element.addEventListener(type, listener, false); } ...Crossbrowser viewport size
2011-02-27
This function allows you to get viewport dimensions (width and height). Viewport is an area that is available for webpage, that is screen resolution - toolbars etc. //get viewport size var viewport = function(){ var viewport = new Object(); viewport.width = 0; viewport.height = 0; // the more standards compliant browsers...Cursor positions and text selections
2011-01-08
For each input in every modern browser there are properties like selectionStart and selectionEnd using which we can easily manipulate cursor position and text selection. Every browser except IE. In IE you will have to deal with text ranges and there is no united way for textareas and input methods, so we'll need to create separate...Rate content using stars
2011-01-05
Here are some javascript functions, that will allow your visitors to rate your content by clicking on stars. We will use same stars, that are used in display rating using stars article. So what we will do, is define two CSS classes with full star and empty star. Then create 3 javascript function. One for onmouseover event that will change...Get document dimensions (cross browser compatible)
2010-11-13
Here are two javascript functions to get document dimensions, which works in all popular browsers. Basic idea is to check all possible values in all possible combinations and take maximal value, so if in one browser this value is undefined, it will be interpreted as 0 and could never be maximal value. Here is a code snippet of those...Get password behind asterix when auto filling forms
2010-11-09
Using different passwords for different websites is almost mandatory nowadays, but it is also pretty hard to keep track of all passwords, so people usually use form fillers. Either it is a built in webrowser or plugin, or standalone application, you just save password once and then auto fill login form without even remembering your password....Notify users about Caps Lock on while logging in
2010-10-16
For security measures in every login form you can't see password which you are entering, thus you don't know if you enter it right. Of course there is a probability that you miss typed it, and that's why you can't log in. But what if you type it for the third time, and you know that you typed the right password? Well then...Function to create table with specified ASCII symbols
2010-07-25
Here is the function, that create table with ASCII symbols from specified ASCII code interval. You can modify it's size and use different styles, onclick function etc. It takes 3 parameters, ID of div element where to attach table, start of ASCII code and end of ASCII code. <div id='chartable'> </div> <script...Select all checkboxes in form
2010-07-21
Here is a piece of code that will allow you to select all checkboxes in specified form, like you can do it in your email account - select all emails. It takes form id as parameter <script type='text/javascript'> function select_allch(id) { var form = document.getElementById(id); var inputs =...Javascript function to check if value is number
2010-07-10
Here is the function, that checks if value is numeric. You can edit valid variable to add more symbols, like "." to check for float numbers or add any other allowed symbols. function is_number(val) { var valid = "0123456789"; var number = true; var symbol; for (i = 0; i < val.length && number ==...Javascript multiple file download queue
2010-07-02
This piece of code allows you to force users to download multiple files one by one using javascript. It can be used to simply download files or use it combination with PHP force download. Although javascript opens file in new window, thus forcing open/save dialog box, it might not work in all browsers. So you may want to modify it to link file...Updating countdown every second using javascript
2010-06-21
Here is a code example how to update countdown on your website every second. You only need to setup start time. <p> <span id='years'></span><span id='y'> years </span> <span id='months'></span><span id='m'> months </span> <span id='days'></span><span id='d'> days...Mirrored text
2010-06-12
Function that not only reverses string, but reverses each line of string, so it looks exactly like in mirror. Check here for example: http://mirrored-text.co.cc/ function rorrim() { reversed = document.getElementById('text').value; revertext = reversed.split(""); revertext = revertext.reverse(); reversed =...How to embed flash objects
2010-05-20
The best way to embed flash object is using SWFObject javascript library. It automatically checks if visitor has flash player, what version, displays corresponding message, and you don't have to worry about those things. To use SWFObject, you need to include javascript library in your <head> tags, then create div, which will...Measure page loading time using javascript
2010-05-19
You can use javascript to measure how long does it take to load your page. It's pretty simple. Get time when your page started to load, get time when it's done and do some math. To get starting time, we need to measure it right after page started to load, it is right after opening <head> tag: <script...jQuery and Mootools conflict
2010-05-18
Since both jQuery and Mootools use symbol $ in their syntax, every time you'll use both of them you'll get a conflict. Web browser won't know to which function you are referring to. To avid this, you can use jQuery no conflict mode. To enable it, you need to put this in your code: <script type="text/javascript"> ...1 2










