I’m trying to write a little bookmarklet that can extract some text from the active page and load that into the clipboard. The extraction is easy enough, but I’m really stuck doing the clipboard-copying part. Currently, I’m just alerting the text and hitting Ctrl+C to copy the text from the message-box, which isn’t ideal. I’ve read How to Copy to
Tag: javascript
HTML5 Video – Percentage Loaded?
Does anyone know what event or property I need to query in order to get a percentage figure of the amount an HTML5 video has loaded? I want to draw a CSS styled “loaded” bar that’s width represents this figure. Just like You Tube or any other video player. So just like you tube a video will play even if
How to use simulate the action of clicking button with jQuery or JavaScript?
I need to use JavaScript to simulate the action of clicking buttons. How do I achieve it? Can I achieve it with jQuery? Answer Yes, you can do it with jquery. Use trigger function. Here documentation. Here is sample:
Convert Data URI to File then append to FormData
I’ve been trying to re-implement an HTML5 image uploader like the one on the Mozilla Hacks site, but that works with WebKit browsers. Part of the task is to extract an image file from the canvas object and append it to a FormData object for upload. The issue is that while canvas has the toDataURL function to return a representation
How to remove numbers from a string?
I want to remove numbers from a string: I want to replace the number 1 number and the question mark ?. It can be any number. I tried the following non-working code. Answer Very close, try: replace doesn’t work on the existing string, it returns a new one. If you want to use it, you need to keep it! Similarly,
Javascript event firing before action occurs
I am trying to write a script so that when I play an embedded sound object, a picture that I also have embedded will change. The problem is that when I load the page, the Javascript code automatically runs even though I don’t click play (autostart is set to false) on the sound object. Does anyone have an idea as
JavaScript property access: dot notation vs. brackets?
Other than the obvious fact that the first form could use a variable and not just a string literal, is there any reason to use one over the other, and if so under which cases? In code: Context: I’ve written a code generator which produces these expressions and I’m wondering which is preferable. Answer (Sourced from here.) Square bracket notation
removeEventListener on anonymous functions in JavaScript
I have an object that has methods in it. These methods are put into the object inside an anonymous function. It looks like this: (there is a lot more code, but this is enough to show the problem) Now I want to stop the event listener in some cases. Therefore I am trying to do a removeEventListener but I can’t
Make an iFrame trigger the body.onclick event
I have a script that attaches a function to be triggered by the the document.onclick event. The problem is that the page has an iframe in it. When the user clicks on the iframe, the document.onclick event does not trigger the function attached to it. Is there any way to fix this? In rare cases, the iframe may have another
Regular expression [Any number]
I need to test for “[any number]” in a string in javascript. how would i match it? Oh, “[” and “]” also need to be matched. so string like “[1]” or “[12345]” is a match. Non match: “[23432” or “1]” So for example: I need to replace input fields name: “items[0].firstname” to “items[1].firstname” thanks Answer UPDATE: for your updated question