-
Code
onbeforeunload
If you want to open a confirm dialog before the user leaves the page (for instance if it contains edited form fields who's values may be lost when the page is reloaded or left), use the onbeforeunload method of the window.
In some browsers you cannot control exactly what text is offered in the dialog This is for security reasons. But at least the user is offered a warning and bailout option when leaving the page.Force download via htaccess
Put the following (and any other file-extensions you want to force a download popup on ) in .htaccess (for instance to prevent the browser from automatically playing a media file in a plugin ).
CDN hosted jQuery with fallback
The following ingenious snippet loads jquery from Google's CDN, but just in case this fails has a dynamic backup jQuery include that loads the file from the server the page being loaded is on ( provided off course it was placed there)
get public directory in ZF
This is not strictly Zend Framework per se, but since all calls are usually redirected to index.php which is in the public root of the ZF installation the following should get the absolute path to the public directory from any files involved from there on forth.
Simple logger script example
This is a simple quick example of a script you can use to answer a cross-domain JSONP call with some json formatted data after ,after writing things to a log file.
jquery placeholder alternative
The html5 placeholder attribute for text inputs and text-areas is very handy. But in case you need to support older browsers that don't support it yet here's an easy jQuery based alternative:
Correct header for dynamic javascript file
In the browser console you may often see the following message when creating javascript files dynamically on the server :
"Resource interpreted as Script but transferred with MIME type text/html"
To prevent this use the following header:example !important usage
You really shouldn't use !important in your CSS unless it's really really important that some specification never changes or is never overridden by some rule later in the CSS on a page. It overrides the cascading principle of CSS, thus making it impossible to overwrite or augment a certain property in some later rule. That said, sometimes it's quite handy when nothing else works.
Check if Ubuntu Linux kernel is 64 bit or 32 bit
The following shell commands can help you check if you are working with a 64 or 32 bit version of Ubuntu Linux
Get last insert id from Zend_Db_Adapter after database insert
To retrieve the primary key of the last inserted row after a database insert in Zend Framework you can use the lastInsertId method:
Hide active link outlines crossbrowser
This should wipe out link outlines on active hyperlinks in all browsers:
404 header in Zend Framework
Here's is how you send a 404 response header in Zend Framework:
Register hook to listen in on all ajax requests in existing application and supply additional callbacks
When customizing an existing web app, listening in on the ajax calls it produces can be a convenient alternative to usin setInterval statements to check when certain transactions complete.
The JQuery ajaxSuccess and ajaxSend methods offer utilities for doing this.
Here's an exemplary codesnippet on how you might use them to create a function allowing you to register additional callbacks with every event.Force file download on mp3 file (or other media)
Browsers have the sometimes annoying habit of automatically playing a media file format they have a plugin for. If you want to force a download dialog instead, here's one way to do it:
Remove orange outline input or textarea in Chrome
To prevent the colored outline from appearing on focused text inputs or text area in webkit / Chrome you can use the following css
determine MySQL version on command line
the following command will print out information what mysql version you are running
password strength validator
You can use the following to validate user password input for strength.
Remove dl dt wrapper tags from Zend Form output
To remove the default dl & dt tags from Zend Form elements you can set the element's decorators manually, and simply omit the HTMLTag decorator:
Wrap the form element and label seperately using the HtmlTag decorator
Here' s how to wrap the form element in a div AND the whole block (label, element, errors etc) in another div using the HtmlTag decorator. So to achieve this:
Add css to head dynamically
You can access an manipulate the head section like you can access all other elements in your DOM. This makes it possible to dynamically add style elements affecting the css rendering of your page:
All countries of the world in an array
Convenient for populating HTML country select fields.
May need to be updated after any political turmoil.JSONP example
Simple example of a JSONP (cross-domain ) request using jQuery and PHP
Append an array to another array
Use array prototype to append an array to another array.
__noSuchMethod__
Executes a function when a non-existent method is called on an object.
Get the hostname, protocol and path from current location object
Here's how you access domain name, protocol and path from the current location object in JavaScript.
Print the current URL with or without querystring
If you need to print the current URL without any query parameters additions you can use the following:
Glow-on-focus input form fields
The following CSS declarations allow you to create text fields that have a ( Twitter-Bootstap like ) glow effect when they are focused on.
-
Comments
-
Questions
Fatal error: Can't use function return value in write context
I'm getting a "Fatal error: Can't use function return value in write context", but don't understand why.
Here's my code:how do you get the ip address on a Unix / Linux Machine?
What command can you use to retrieve the ip address on a Unix / Linux Machine?
$.getJSON
How can I prevent clientside caching in IE8 when using jQuery getJSON.
Client side caching when using this method doesn't happen when I use FF or Webkit, but IE uses cached data.How can I automatically turn all email adresses in an html text into mailto links?
I'm trying to link a bunch of email addresses
-
Links
Create a logger in Zend Framework using application.ini
How to setup a logger in Zend applications using application ini and the bootstrap
Createjs suite
CreateJS is a suite of modular libraries and tools which work together to enable rich interactive content on open web technologies via HTML5. These libraries are designed to work completely independently, or mixed and matched to suit your needs. The CreateJS Suite is comprised of: EaselJS, TweenJS, SoundJS, PreloadJS, and Zoë.
Here's a useful tutorial aimed specifically at Actionscript / Flash developers looking for familiar API's in a JavaScript / HTML5 environment: http://active.tutsplus.com/tutorials/html5/getting-started-with-easeljs-a-flash-like-interface-for-the-html5-canvas
Socialite.js
Socialite provides an easy way to implement social sharing buttons.
Socialite won't cause document rendering to hang while waiting for social media.Spin.js
Spin.js is a image-less, customizable JavaScript and CSS3 based spinner animation script with VML fallback for older IE versions.
All it takes is one JavaScript include.
Use it when ajax-loading content or other processes that make the user wait.
Pie menu (like Path menu)
This is a CSS3 / jQuery based pie menu based on the menu used in the popular Path mobile app.
Some testing revealed that it does require a modern browser for proper execution, so do provide proper fallbacks when implementing.Toastr
Toastr is a simple extendable and customizable JavaScript notification library for Growl / Gnome like non-blocking notifications. It allows you to create simple toasts with HTML5 and JavaScript.
It is inspired by the similar http://opensource.srirangan.net/notifier.jsAnimate.css - Just-add-water CSS animation
Here's a neat little CSS library you can start using to replace some of your JavaScript based animations and effects. Animate.css is a collection of cross-browser animations for you to use in your projects. Great for emphasis, home pages, sliders, and general eye candy.
Just another example demonstrating that the new features of CSS-3 are slowly putting style sheets back in charge of what they were meant for: lay-out, style and presentation.
Quick look at the math of animations in javascript
This Smashing Magazine article offers a quick introduction into the basic principles behind using exponentials, sine waves and general geometry for creating animations in JavaScript.
The article comes with a lot of examples built in JSFiddle, allowing you to tweak and play around and create custom effects with some of the introduced math principles.
Phonegap
PhoneGap is an HTML5 app platform that allows you to author native applications with web technologies and get access to APIs and app stores. PhoneGap allows you to write native mobile apps in HTML and JavaScript and deploy them to all the dominant mobile platforms.
The PhoneGap code was contributed to the Apache Software Foundation (ASF) under the name Apache Callback in October 2011. It is currently under incubation until it can become a full Apache project. Through the ASF, future PhoneGap development will ensure open stewardship of the project. It will always remain free and open source under the Apache License, Version 2.0.
Website performance tools and resources link list
Some very useful web-performance related links here!
Sam Saffron presents a long list of online tools that can help you with optimizing the performance of your websites and applications.
A must-read for front-end developers.
Muro html5 editor
Muro is a browser based HTML5 drawing application released back in August 2010 as a celebratory offering for deviantArt's 10th birthday. Although Muro serves mainly as an application for use by deviantArt members, it also serves as a nice proof of concept with regards to the possibilities the HTML5 canvas element offers for building drawing applications.
Muro has a bunch of features such as 20 brushes (some free, others require payment), layers, and different filters. You can use the Muro with a WACOM tablet.
Scrollpath
jQuery scrollpath is an interesting project experimenting with scroll directions and paths. Basically it allows you to define custom paths for scrolling through your content. The scrollpath demo says it all.
jQuery knob demo
On http://anthonyterrien.com I found an interesting canvas based knob controller interface element. It is implemented as jQuery plugin, but it does of course require a Canvas supporting browser.
HTML5 video player comparison
This HTML5 Video Player Comparison table offers some help with choosing an appropriate video player for your next project.
HTML5 video can still be a bit of a pain to implement practically with all the browser idiosyncrasies and necessity for supplying (Flash) fallback.
This site offers help by showing the pro's and cons of some of the most commonly used scripts.
How to Master Ubuntu’s Unity Desktop: 8 Things You Need to Know
Howtogeek:
Ubuntu’s Unity desktop is a change of pace, whether you’re coming from Windows or another Linux
distribution with a more traditional interface. Unity has its own way of doing things, including powerful keyboard shortcuts.
If you’re not using Ubuntu, you can play with Unity in your browser using the Ubuntu online tour website. This guide is targeted at new Unity users, but even experienced Ubuntu users might discover a few new tricks.
screenfull.js
The Fullscreen API is fairly new with growing support but the implementation varies across browsers. Screenfull.js is a simple script trying to change that.
PEP - A lightweight plugin for kinetic-drag on mobile/desktop
Pep was built out of a need for kinetic drag support for both mobile and desktop devices (click & drag). It uses the best of jQuery's animate functions along with CSS3 animations to bring full-blown kinetic drag that works on all HTML5-ready devices.
TouchTouch - A Touch Optimized Gallery Plugin
jQuery plugin that turns a collection of photos on a webpage into a touch-friendly mobile gallery. It works on all major browsers (except for IE7 and below) and most importantly is specifically designed with iOS and Android in mind.
Real shadow
jQuery Plugin that casts photorealistic shadows. Perfect for eye-catching demos and landing pages.
It works in any browser supporting CSS box-shadow property.Storage.js
Simple HTML5 page edits. Storage.js uses the new HTML5 contenteditable attribute and localStorage to enable inline html page editing
lake.js
Lake.js takes an img element and inserts a canvas element displaying the image and its flipped reflection directly after the img element, creating an illusion of a rippling reflection in water.
Direction-aware hover effect using CSS3 and jQuery.
How to create a direction-aware hover effect using CSS3 and jQuery. The idea is to slide in an overlay from the direction we are moving with the mouse.
jquery fullscreen plugin
This jQuery plugin provides a simple to use mechanism to control the new fullscreen mode of modern browsers. Currently only newer Webkit-based browsers (Like Chrome) and Firefox provide this new fullscreen feature.
Cloud Zoom
Cloud Zoom is a free jQuery image zoom plugin, a comparable alternative to products such as Magic Zoom. Compared to the popular jQZoom plugin, Cloud Zoom is smaller, has more features and more robust compatability across browsers.
Speakker - Crossbrowser Audio solution featuring HTML5
Comes out of the box in two variations and with incredible options of customization: Flexible dimensions, unlimited colors and two different button sets for light and dark themes.
Featuring the technology of Projekktor it comes with cross-browser compability, Flash-fall back plus optional
social- and artists information links.
fittext js
FitText makes font-sizes flexible. Use this plugin on your fluid or responsive layout to achieve scalable headlines that fill the width of a parent element.
This is for gigantic (header / logo) display text only!
lettering.js
Web type is exploding all over the web but CSS currently doesn't offer complete down-to-the-letter control. So here's a a jQuery plugin to give you that control.
Chosen
Chosen is a JavaScript plugin that makes long, unwieldy select boxes much more user-friendly. It is currently available in both jQuery and Prototype flavors.
Ajax AutoComplete for jQuery
Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields.
Built with focus on performance - results for every query are cached and pulled from local cache for the same repeating query. If there are no results for particular query it stops sending requests to the server for other queries with the same root.
uniform.js
Uniform masks your standard form controls with custom themed controls. It works in sync with your real form elements to ensure accessibility and compatibility.
Check out this interesting discussion / comparison on some of the similar tools out there:
http://stackoverflow.com/questions/1482586/comparison-between-corona-phonegap-titanium
Posted in Phonegap
Mobile
@ 16th May 2012
by anonymous
hmm,
$_GET is not a function, but an array. You're using it like a function call.
That's not going to work.
Your code should be:
Posted in Fatal error: Can't use function return value in write context
PHP
@ 12th May 2012
by anonymous
This works much better cross browser:
Posted in Force download via htaccess
.htaccess
@ 21st April 2012
by anonymous
You will miss parameters containing the equals sign (=)
maybe the following is better although you'll miss parameters containing questionmarks: But those shouldn't be in urls anyhow
Posted in Retrieve get name-value pairs from url
Javascript
@ 19th April 2012
by anonymous
that 's great thanks
Posted in Set constants in ZF application ini file
Zend Framework
@ 13th April 2012
by anonymous
use the second to prevent further code execution
Posted in 404 header in Zend Framework
Zend Framework
@ 2nd April 2012
by anonymous
How about changing the regular expression to :
Posted in Retrieve get name-value pairs from url
Javascript
@ 2nd April 2012
by anonymous
You can use the following:
Posted in how do you get the ip address on a Unix / Linux Machine?
Unix/Linux
@ 26th March 2012
by Snokie Eikons
Taken from the Twttr. Bootstrap css:
Posted in Glow-on-focus input form fields
CSS
@ 8th March 2012
by anonymous
You should also clean the uploaded file's name like so:
Posted in Securing file uploads in php
PHP
@ 26th February 2012
by anonymous
Or to keep any already registered window.onload callbacks intact:
Posted in document onload or window onload event
Javascript
@ 23rd February 2012
by anonymous
If you still find this is failing in Internet Explorer try using:
Posted in document onload or window onload event
Javascript
@ 13th February 2012
by anonymous
of course that regular expression will not hold water in many cases. For a better regex look here for example:
http://www.regular-expressions.info/email.html
Posted in How can I automatically turn all email adresses in an html text into mailto links?
Javascript
@ 28th January 2012
by anonymous
You could put the following directive in your .htaccess file :
Posted in Magic quotes
PHP configuration
@ 25th January 2012
by 1boeman
You can just add a random parameter to the call, traditional cache breaker style:
Posted in $.getJSON
jQuery
@ 25th January 2012
by anonymous
Try this:
Posted in How can I automatically turn all email adresses in an html text into mailto links?
Javascript
@ 24th January 2012
by 1boeman
yes it works
Posted in Simple PHP captcha script
PHP
@ 15th January 2012
by anonymous
ten times
Posted in Simple PHP captcha script
PHP
@ 15th January 2012
by anonymous
very nice.
Posted in Simple PHP captcha script
PHP
@ 11th January 2012
by anonymous
f
Posted in Simple PHP captcha script
PHP
@ 10th January 2012
by anonymous
This is great for rss text data. What do you do about an image that is passed? How is it processed and added to a for example?
Posted in Parse RSS XML with jQuery
jQuery
@ 6th January 2012
by anonymous
I m very new to php.
I use this but captcha not showing image?
Thx in Advance
Regrds
Posted in Simple PHP captcha script
PHP
@ 31st December 2011
by anonymous
test
Posted in Simple PHP captcha script
PHP
@ 29th December 2011
by anonymous
kdkfgkdf gkdf gkdfg kfd kdk alert("jjjjjjjjjjjjj")
Posted in jQuery .each loop example
jQuery
@ 21st December 2011
by anonymous
Voor degene die het nog interreseert ; de oplossing voor meerdere mouseovers :-)
De clou zit hem in het mouseover gedeelte, de name moet uniek zijn.
script :
if (document.images){
image1 = new Image
image2 = new Image
image1.src = 'images/home_button.png'
image2.src = 'images/home_button_over.png'
image3 = new Image
image4 = new Image
image3.src = 'images/reiki_button.png'
image4.src = 'images/reiki_button_over.png'
}
Veel plezier ermee !
Posted in Javascript mouseover image swap
Javascript
@ 10th December 2011
by anonymous
I agree, simple scripts and easy to adjust, a good starting point.
Thanks for the post.
Posted in Simple PHP captcha script
PHP
@ 29th November 2011
by anonymous
base64 is not a native php function
You probably meant:
base64_encode(mt_rand()),0,$length);
Posted in Generate random password with php
PHP
@ 27th November 2011
by anonymous
Can somebody tell me whats wrong with my php code? (write.php)
alert('Success.');
history.back(1);
alert('error.');
history.back(1);
waiting for comment and ayberkc@hotmail.com is my e-mail.
Posted in Simple PHP captcha script
PHP
@ 26th November 2011
by anonymous
exactly what I needed. Thanks
Posted in jQuery check if dom element exists
jQuery
@ 26th November 2011
by anonymous
Nice code....
Posted in Clear form with jQuery
jQuery
@ 16th November 2011
by anonymous
Simples e bem feito
Posted in Simple PHP captcha script
PHP
@ 14th November 2011
by anonymous
That is a great looking script, how would I call the buttons up in my html file if I were to add the function to a remote file called something like sociallinks.js
Can you help?
Posted in Social media icon script
jQuery
@ 14th November 2011
by anonymous
Very nice example! Thanks !
Posted in XML to string and string to XML in Javascript
Javascript
@ 12th November 2011
by anonymous
10x
Posted in Simple PHP captcha script
PHP
@ 11th November 2011
by anonymous
Ik heb hetzelfde probleem als Tim. Is de juiste code al gevonden?
gr,
Pascal
Posted in Javascript mouseover image swap
Javascript
@ 8th November 2011
by anonymous
excist (!) ?
Posted in Write to file example in PHP
PHP
@ 8th November 2011
by anonymous
Excisting?
Existing.
Posted in Altering excisting table
SQL
@ 8th November 2011
by anonymous
wot about just :
Array.prototype.shuffle = function() {
var i=this.length,p,t;
while (i--) {
p = Math.floor(Math.random()*i);
t = this[i];
this[i]=this[p];
this[p]=t;
}
};
That way p is taken from a diminishing pool and can\'t be assigned a value that has already been assigned? Simpler too. Seems to work anyway.
Posted in Array shuffle function
Javascript
@ 7th November 2011
by anonymous
Problem with IE9
Please change this:
$(messageHolder).css('bottom', 0);
To:
$(messageHolder).css({position:'absolute',bottom:0});
Posted in jQuery sticky footer
jQuery
@ 7th November 2011
by anonymous
Whoops! Replied to the previous comment.
Could I get an example of this? I'm trying to make the mute button work with these calls here: www.friedmanllp.com/home3.php and I'm having some errors. Need to pass a pass a click event (the mute button) to the other flash file and turn off and on the sound.
Thanks in advance.
Posted in Call javascript function from AS3 and viceversa
Actionscript3
@ 4th November 2011
by anonymous