I am working with some code that needs to be run as a page, and if it’s being run as a Chrome Extension, I want to be able to do additional things. What I’m using is: This seems like a good capability detection. Using user agent string causes me trouble because it’s the same no matter the context (web page
Tag: javascript
How to change date format (MM/DD/YY) to (YYYY-MM-DD) in date picker
I have following datepicker script: Now dateformat is MM/DD/YY .how to change the date format to YYYY-MM-DD? Answer Use the dateFormat option Demo at http://jsfiddle.net/gaby/WArtA/
html5, what is isContentEditable?
chrome supports the isContentEditable property (lists it in the “Inspect Element”), but reports false for INPUT, FORM – actually, everything. too me, for example, seems that INPUT, non-readonly, should be true. does anybody know what’s going on? Answer isContentEditable doesn’t have anything to do with forms and input boxes. It was designed to be a way to flag inline editable
Why is event.ctrlKey returning undef?
I am calling a JavaScript function when an option is selected in a select element like so: The function does something like this: According to the alert, e.ctrlKey is undefined – I thought this was supposed to return either true or false? What am I missing here? Answer As per the standard, the attribute ctrlKey is only available on MouseEvents
Only detect click event on pseudo-element
Please see this fiddle: http://jsfiddle.net/ZWw3Z/5/ My code is: I would like to trigger a click event only on the pseudo-element (the red bit). That is, I don’t want the click event to be triggered on the blue bit. Answer This is not possible; pseudo-elements are not part of the DOM at all so you can’t bind any events directly to
Include jQuery in the JavaScript Console
Is there an easy way to include jQuery in the Chrome JavaScript console for sites that do not use it? For example, on a website I would like to get the number of rows in a table. I know this is really easy with jQuery. The site does not use jQuery. Can I add it in from the command line?
JavaScript: Scroll to selection after using textarea.setSelectionRange in Chrome
A JavaScript function selects a certain word in a textarea using .setSelectionRange(). In Firefox, the textarea automatically scrolls down to show the selected text. In Chrome (v14), it does not. Is there a way to get Chrome to scroll the textarea down to the newly selected text? jQuery solutions are welcome. Answer Here is a simple and efficient solution in
How to trim a string to N chars in Javascript?
How can I, using Javascript, make a function that will trim string passed as argument, to a specified length, also passed as argument. For example: Anyone got ideas? I’ve heard something about using substring, but didn’t quite understand. Answer Why not just use substring… string.substring(0, 7); The first argument (0) is the starting point. The second argument (7) is the
event.target on Firefox
Works fine on Google Chrome and IE but not on Firefox. Tried it on Google. Google says event.srcElement (works on IE but not on Firefox) so I have added event.target but still not working. Is there anymore changes I need to do to work on Firefox? By the way I’m using 3.5 version of Firefox. Please help me to make
How to include javaScript file in xslt
How can I include/import javaScript file/libary in xslt file. Answer If you need to use the javascript in the transformation (for example, it contains a set of extension functions that are called within the transformation), you need to put the javascript contents (at least that of one javascript file) in a separate XSLT stylesheet file, using the proper extension element