1. Minimise Access to Page Elements
- 3月 30 週三 201600:57
JavaScript 複習筆記 -新觀念
- 6月 26 週五 201504:30
Javascript 運算子 === (identity operator) vs == (equality operator)
識別運算子:===、!==
英文 : These operators behave the same as the equality operators, except that no type conversion is done.
中文 : 這些運算子的行為方式和等號比較運算子相同,但是有一點例外,就是不會進行型別轉換。 如果兩個運算式的型別不同,這些運算式一定會傳回 false。
- 4月 27 週一 201501:49
JScript – Convert Image To Base64
Yesterday I was updating an HTA (HTML Application) and needed to figure out how to convert an image into a base64 code that could be used in a stylesheet. I needed this to be able to embed an image in the source code instead of referencing an actual image. For this reason I wrote the following function (with the help of this post):
But it cannot work in IE9. I get an error saying Access is denied, IE doesn't allow manipulation of the type="file" input element from javascript due to security reasons. Setting the filename or invoking a click event to show the browser dialog will result in an "Access is denied" error on the form submit - Internet Explorer is clever about remembering what methods have been invoked.
function convertImageToBase64(filePath) { var inputStream = new ActiveXObject('ADODB.Stream'); inputStream.Open(); inputStream.Type = 1; // adTypeBinary inputStream.LoadFromFile(filePath); var bytes = inputStream.Read(); var dom = new ActiveXObject('Microsoft.XMLDOM'); var elem = dom.createElement('tmp'); elem.dataType = 'bin.base64'; elem.nodeTypedValue = bytes; var ret = 'data:image/png;base64,' + elem.text.replace(/[^A-Z\d+=\/]/gi, '');}But it cannot work in IE9. I get an error saying Access is denied, IE doesn't allow manipulation of the type="file" input element from javascript due to security reasons. Setting the filename or invoking a click event to show the browser dialog will result in an "Access is denied" error on the form submit - Internet Explorer is clever about remembering what methods have been invoked.
1
