Category: JavaScript

How to create Current Page with JavaScript?

This is like a replacement for PHP’s SCRIPT_NAME with JavaScript. location.href.split(‘/’).pop(); For example with this URL: http://css-tricks.com/examples/ScriptName/index.php This code: document.write( location.href.split(‘/’).pop() ); Would write to the page: “index.php” Reference URL

How to disable javascript in web browser?

JavaScript is supported by the Camino, Firefox, Google Chrome, iCab, Internet Explorer, Konqueror, Netscape, OmniWeb, Opera, Safari and SeaMonkey Web browsers, and so almost everyone can use it. However, some people worry that JavaScript...

How to Drag an element without jQuery UI

It doesn’t have all the fancy callbacks and options, but hey, it makes things draggable (and with a specified handle optionally). (function($) { $.fn.drags = function(opt) { opt = $.extend({handle:””,cursor:”move”}, opt); if(opt.handle === “”)...

Cookie Getter/Setter using javascript?

/** * Gets or sets cookies * @param name * @param value (null to delete or undefined to get) * @param options (domain, expire (in days)) * @return value or true */ _.cookie =...

Array of Country Names using Javascript

var country_list = [“Afghanistan”,”Albania”,”Algeria”,”Andorra”,”Angola”,”Anguilla”,”Antigua & Barbuda”,”Argentina”,”Armenia”,”Aruba”,”Australia”,”Austria”,”Azerbaijan”,”Bahamas”,”Bahrain”,”Bangladesh”,”Barbados”,”Belarus”,”Belgium”,”Belize”,”Benin”,”Bermuda”,”Bhutan”,”Bolivia”,”Bosnia & Herzegovina”,”Botswana”,”Brazil”,”British Virgin Islands”,”Brunei”,”Bulgaria”,”Burkina Faso”,”Burundi”,”Cambodia”,”Cameroon”,”Cape Verde”,”Cayman Islands”,”Chad”,”Chile”,”China”,”Colombia”,”Congo”,”Cook Islands”,”Costa Rica”,”Cote D Ivoire”,”Croatia”,”Cruise Ship”,”Cuba”,”Cyprus”,”Czech Republic”,”Denmark”,”Djibouti”,”Dominica”,”Dominican Republic”,”Ecuador”,”Egypt”,”El Salvador”,”Equatorial Guinea”,”Estonia”,”Ethiopia”,”Falkland Islands”,”Faroe Islands”,”Fiji”,”Finland”,”France”,”French Polynesia”,”French West Indies”,”Gabon”,”Gambia”,”Georgia”,”Germany”,”Ghana”,”Gibraltar”,”Greece”,”Greenland”,”Grenada”,”Guam”,”Guatemala”,”Guernsey”,”Guinea”,”Guinea Bissau”,”Guyana”,”Haiti”,”Honduras”,”Hong Kong”,”Hungary”,”Iceland”,”India”,”Indonesia”,”Iran”,”Iraq”,”Ireland”,”Isle of Man”,”Israel”,”Italy”,”Jamaica”,”Japan”,”Jersey”,”Jordan”,”Kazakhstan”,”Kenya”,”Kuwait”,”Kyrgyz Republic”,”Laos”,”Latvia”,”Lebanon”,”Lesotho”,”Liberia”,”Libya”,”Liechtenstein”,”Lithuania”,”Luxembourg”,”Macau”,”Macedonia”,”Madagascar”,”Malawi”,”Malaysia”,”Maldives”,”Mali”,”Malta”,”Mauritania”,”Mauritius”,”Mexico”,”Moldova”,”Monaco”,”Mongolia”,”Montenegro”,”Montserrat”,”Morocco”,”Mozambique”,”Namibia”,”Nepal”,”Netherlands”,”Netherlands Antilles”,”New Caledonia”,”New...

How to copy to the clipboard in JavaScript?

Automatic copying to clipboard may be dangerous, therefore most browsers (except IE) make it very difficult. Personally, I use the following simple trick: function copyToClipboard (text) { window.prompt (“Copy to clipboard: Ctrl+C, Enter”, text);...

How to avoid Java Code in JSP-Files?

The use of scriptlets (those <% %> things) in JSP is indeed highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language, those ${} things) over a decade ago. The major disadvantages of scriptlets are: Reusability: you can’t reuse scriptlets. Replaceability: you can’t make...

How can I get query string values?

You don’t need jQuery for that purpose. You can use the pure JavaScript: function getParameterByName(name) { name = name.replace(/[\[]/, “\\\[“).replace(/[\]]/, “\\\]”); var regexS = “[\\?&]” + name + “=([^&#]*)”; var regex = new RegExp(regexS);...