Recent Notes
Displaying keyword search results 1 - 7
Created by Dr. Xi on September 11, 2008 23:06:18
Last update: October 06, 2010 03:16:13
Firefox and Google chrome has native support for the trim function for a String. IE (as of IE 8.0) does not provide a trim function for String. Using the JavaScript Executor , if you execute:
'abcd '.trim
you get:
function trim() { [native code] }
in Firefox and Google Chrome. But you get nothing in IE. If you try to execute the trim method on a String:
'abcd '.trim()
you get this in IE:
TypeError: Object doesn't support this property or...
In order to have the trim function across all browsers, define this function:
if(typeof String.prototype.trim !== 'function') {
...
Or, if you use jQuery, you can use $.trim()
Created by James on September 10, 2010 23:01:14
Last update: September 10, 2010 23:01:14
By default, heights for jQuery UI tab panels expand or contract depending on the height of each tab. The code snippet here sets the height of all tabs to be equal to that of the container.
<!DOCTYPE html>
<html>
<head>
<title>jQu...
Created by James on September 03, 2010 15:28:59
Last update: September 03, 2010 15:28:59
For a JavaScript array, the push method appends an element to the end, the unshift method inserts an element to the beginning.
The following code yields the array [1, 2, 3, 4] :
a = [];
a.push(3);
a.push(4);
a.unshift(2...
Created by James on June 30, 2010 19:04:45
Last update: July 03, 2010 21:24:33
Technically, file upload cannot be handled by Ajax, because XMLHttpRequest (XHR) does not handle file inputs. All techniques not using Flash rely on an invisible iframe as the upload form submit target. JavaScript then grabs the response content from the iframe and present it, giving the same illusion as Ajax. webtoolkit AIM The technique by webtoolkit is very simple. It involves 3 simple steps: include the AIM script, implement the start/finish JavaScript functions, and add an onsubmit handler to the normal file upload form. The hooked up form looks like:
<head> <script type="text/javascript" src="webt... The AIM script is also quite simple: /** * * AJAX IFRAME METHOD (AIM) * http... The above code only supports HTML responses. In order to support JSON responses, the above...
Created by James on June 30, 2010 20:14:28
Last update: July 03, 2010 18:41:12
The HTML page
<!DOCTYPE html>
<html>
<head>
<title>jQu...
Client Side Code
// called before upload submit
function sta...
Server Side Code
Using Apache Commons FileUpload as example.
Upload code (responds to fileUpload.do ):
final HttpSession session = httpServletRequest...
Progress code (responds to uploadProgress.do ):
HttpSession session = httpServletRequest.getSe...
Created by James on July 05, 2009 02:21:15
Last update: July 05, 2009 02:25:20
This is a JavaScript wrapper for Bare Naked App's progress bar.
As usual, download their images and add this to the CSS:
img.progressBar {
background: white url(images...
Then, add my JavaScript function, which takes a parent HTML element as input and returns the progress bar object with a setValue method:
function createProgressBar(elem) {
var img = d...
Test code:
<html>
<head>
<!-- setup code START -->
...
Created by Dr. Xi on January 09, 2008 03:47:31
Last update: August 31, 2008 16:33:28
Many times I need to test some JavaScript snippet before writing code. Maybe I forgot how some JavaScrpit function is supposed to work, maybe I saw some tricky JavaScript code and needed to figure out how it worked. I used MS scripting host for while, but found it cumbersome. Plus, DOM objects are not available in the scripting host.
Below is a simple HTML page I created for this task. You can use the Logger.debug method to output debugging messages.
<html>
<head>
<script language="JavaScript" ...
For example, if you enter
Logger.debug(unescape('http%3a%2f%2fwww.56.com%2fn...
into the text area and click "Execute", you get the following output:
http://www.56.com/n_v166_/c33_/17_/
bcd
[obj...