Posts filed under ‘JavaScript’
encodeURIComponent ColdFusion
JavaScript encodeURIComponent converted to ColdFusion. This is used for OAuth.
<cffunction access="private" name="doPercentEncode" output="false" returntype="string"> <cfargument name="stringToEncode" type="string" required="yes"> <cfscript> variables.encodedString = arguments.stringToEncode; variables.encodedString = replace( variables.encodedString, "!", "%21", "all" ); variables.encodedString = replace( variables.encodedString, "*", "%2A", "all" ); variables.encodedString = replace( variables.encodedString, "##", "%23", "all" ); variables.encodedString = replace( variables.encodedString, "$", "%24", "all" ); variables.encodedString = replace( variables.encodedString, "%", "%25", "all" ); variables.encodedString = replace( variables.encodedString, "&", "%26", "all" ); variables.encodedString = replace( variables.encodedString, "'", "%27", "all" ); variables.encodedString = replace( variables.encodedString, "(", "%28", "all" ); variables.encodedString = replace( variables.encodedString, ")", "%29", "all" ); variables.encodedString = replace( variables.encodedString, "@", "%40", "all" ); variables.encodedString = replace( variables.encodedString, "/", "%2F", "all" ); variables.encodedString = replace( variables.encodedString, "^", "%5E", "all" ); variables.encodedString = replace( variables.encodedString, "~", "%7E", "all" ); variables.encodedString = replace( variables.encodedString, "{", "%7B", "all" ); variables.encodedString = replace( variables.encodedString, "}", "%7D", "all" ); variables.encodedString = replace( variables.encodedString, "[", "%5B", "all" ); variables.encodedString = replace( variables.encodedString, "]", "%5D", "all" ); variables.encodedString = replace( variables.encodedString, "=", "%3D", "all" ); variables.encodedString = replace( variables.encodedString, ":", "%3A", "all" ); variables.encodedString = replace( variables.encodedString, ",", "%2C", "all" ); variables.encodedString = replace( variables.encodedString, ";", "%3B", "all" ); variables.encodedString = replace( variables.encodedString, "?", "%3F", "all" ); variables.encodedString = replace( variables.encodedString, "+", "%2B", "all" ); variables.encodedString = replace( variables.encodedString, "\", "%5C", "all" ); variables.encodedString = replace( variables.encodedString, '"', "%22", "all" ); return variables.encodedString; </cfscript> </cffunction>
Password Value as Text
I was working on a design the other day that only had text fields with no labels, the label was in the text field and would disappear when clicked on
Continue Reading November 17, 2009 at 1:53 am Taco Fleur Leave a comment
Convert HTML entities from XML in JavaScript
Sometimes you get passed a string from XML and it can contain HTML entities like the following
&
<
>
"
©
®
«
»
'
If you write the string with JavaScript then you get something like didn't instead of didn’t
I’ve searched around for a function that could handle this but could not find one, so I wrote my own. I thought I’d share it with the world!
The following will convert & to &, convert ' to ‘ etc.
Following is the code, if you need help implementing it, I’m more than happy to explain how you install and run this function in return for a text link on your website, now that’s cheap as, considering I normally charge $140 an hour 😉
String.prototype.trim = function () { return this.split( /\s/ ).join( " " ); } String.prototype.convertHTMLEntity = function () { var myString = this; myString = myString.replace( /\&/g, '&' ); myString = myString.replace( /\</g, '<' ); myString = myString.replace( /\"/g, '"' ); myString = myString.replace( /\©/g, '©' ); myString = myString.replace( /\®/g, '®' ); myString = myString.replace( /\«/g, '«' ); myString = myString.replace( /\&raqou;/g, '»' ); myString = myString.replace( /\'/g, "'" ); return myString; }
Convert Microsoft Word Characters
I’ve written a JavaScript function a while ago that converts Microsoft Word Characters (crap) to valid HTML characters. Till today I didn’t realize how valuable the function is, it could probably do with some expansion on what it converts so any help to improve is much appreciated.
Continue Reading March 31, 2009 at 5:18 am Taco Fleur 1 comment
Recent comments