JavaScript is a powerful programming language that is widely used for web development. In order to become a proficient JavaScript developer, it is essential to have a solid understanding of the modern features and best practices.
Weiterlesen „Mastering Modern JavaScript with a Cheat Sheet“Schlagwort: javascript
Php Sleep function in javascript
Here is a tidy javascript function that I found on stack overflow to mimic PHP’s usleep function which has been useful when testing javascript.
Weiterlesen „Php Sleep function in javascript“
Get last character in a string using PHP
Similar to how you get the last character in a string using Javascript, you just slice off the last N characters.
Weiterlesen „Get last character in a string using PHP“
Online tools to tidy, format and optimize code
Here are a bunch of online tools I use to tidy, format and optimize code.
Weiterlesen „Online tools to tidy, format and optimize code“
Change Float style with Javascript
If you would like to change the float style of some element using javascript, then use the following.
[source language=“javascript“]
var element = document.getElementById( ’some_element_id‘ );
element.style.cssFloat = ‚left‘;
[/source]
Faster Javascript Trim
Want the best way to trim a sting in javascript?
A while ago, I came across a post on such a subject. It was written a few years ago but it’s still as relevant and useful as ever.
Addslashes and stripslashes in Javascript
Simple one. If you need to add/remove escape slashes to/from a string, use the following code.
Weiterlesen „Addslashes and stripslashes in Javascript“
Javascript library to manage Flash Local Stored Objects
In an earlier post, I explained how to use Javascript to talk to a Flash file to create and read Local stored objects, a.k.a. Flash cookies.
The only hitch I met was that I couldn’t create cross domain cookies this way as I was hitting the same domain policy. However as pointed out in the comments, it is possible, and simple too… I just needed to add… Weiterlesen „Javascript library to manage Flash Local Stored Objects“
Create a smart, cross browser floating menu using Javascript
I recently wrote a Javascript library to show a floating menu that works cross browser and displays the menu based on a set of co-ordinates that you pass it.
The floating menu is just an absolute div that is hidden from view.
The library is smart in the sense that it determines where best to display the menu. It works out where you have scrolled to on the page and figures out if there is space at the top or bottom and to the left or right of where ever your target co-ordinates are.
This is useful where you want to display a menu, or some div, but you don’t know (or care) where the menu is going to be needed on the page.
Weiterlesen „Create a smart, cross browser floating menu using Javascript“
JavaScript Tricks; URLEncode, Foreach and Remove last character
I have come across some neat (if not mind blowing) tricks with JavaScript recently.
Firstly, I needed JavaScript code that copied PHP’s urlencode().
This function returns an encoded string where all non-alphanumeric characters except – _ . are replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.
JavaScript has 2 functions to emulate urlencode(), but both fall short…
The escape function encodes all non-alphanumeric characters except * @ / + – _ .
The encodeURIComponent function encodes all non-alphanumeric characters except spaces and ! ‚ ( ) * ~
The winner for me though is encodeURIComponent as it encodes all UTF-8 characters while escape only encodes ISO Latin characters.
With this in hand, mozilla help provide a neat function.
Weiterlesen „JavaScript Tricks; URLEncode, Foreach and Remove last character“
