Skip to content
Advertisement

what is the [object Window]?

Google Translate, has some bookmark let for translate with 1 click, for example: This javascript code, opens the translator page in the current page (target=_self), but I want it opens a new window (tab) for translate. so changed to: My problem is here: when I run that code, it opens a new window for translate, and do it; but the

using javascript’s .insertBefore to insert item as last child

I so miss jQuery. I’m working on a project where I need to get my hands dirty with good ‘ol plain Javascript again. I have this scenario: Via javascript, I want to be able to insert a new node before or after any of those children. While javascript has an insertBefore, there is no insertAfter. Insert before would work fine

How to find the 2nd closest ancestor in jQuery?

My DOM looks something like this: When the used clicks on ‘Edit’, I want to change the outer <li> to <li class=”selected>. I tried something like this, but this is not working: Any help is appreciated. Answer Go up a parent: It wasn’t working because closest starts with the current element, and so if you call it on something that

How do I style HTML5 canvas text to be bold and/or italic?

I’m printing text to a canvas in a pretty straight forward way: But how can I change the text to bold, italic or both? Any suggestions to fix that simple example? Answer From the MDN documentation on CanvasRenderingContext2D.font: The CanvasRenderingContext2D.font property of the Canvas 2D API specifies the current text style to use when drawing text. This string uses the

Convert JS date time to MySQL datetime

Does anyone know how to convert JS dateTime to MySQL datetime? Also is there a way to add a specific number of minutes to JS datetime and then pass it to MySQL datetime? Answer or even shorter: Output: For more advanced use cases, including controlling the timezone, consider using http://momentjs.com/: For a lightweight alternative to momentjs, consider https://github.com/taylorhakes/fecha

Converting hexadecimal to float in JavaScript

I would like to convert a number in base 10 with fraction to a number in base 16. All is well there. Now I want to convert it back to decimal. But now I cannot write: As it doesn’t return the decimal part. And I cannot use parseFloat, since per MDC, the syntax of parseFloat is It wouldn’t have been

Copy text to clipboard from bookmarklet

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

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

Advertisement