What is the difference between screenX/Y, clientX/Y and pageX/Y?

Here’s a picture explaining the difference between pageY and clientY. Same for pageX and clientX, respectively. pageX/Y coordinates are relative to the top left corner of the whole rendered page (including parts hidden by scrolling), while clientX/Y coordinates are relative to the top left corner of the visible part of the page, “seen” through browser … Read more

jQuery .load() call doesn’t execute JavaScript in loaded HTML file

You are loading an entire HTML page into your div, including the html, head and body tags. What happens if you do the load and just have the opening script, closing script, and JavaScript code in the HTML that you load? Here is the driver page: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”> <html … Read more

Firing a Keyboard Event in Safari, using JavaScript

I am working on DOM Keyboard Event Level 3 polyfill . In latest browsers or with this polyfill you can do something like this: element.addEventListener(“keydown”, function(e){ console.log(e.key, e.char, e.keyCode) }) var e = new KeyboardEvent(“keydown”, {bubbles : true, cancelable : true, key : “Q”, char : “Q”, shiftKey : true}); element.dispatchEvent(e); //If you need legacy … Read more

How to remove the border highlight on an input text element

In your case, try: input.middle:focus { outline-width: 0; } Or in general, to affect all basic form elements: input:focus, select:focus, textarea:focus, button:focus { outline: none; } In the comments, Noah Whitmore suggested taking this even further to support elements that have the contenteditable attribute set to true (effectively making them a type of input element). … Read more

is there a css hack for safari only NOT chrome?

UPDATED FOR MONTEREY & SAFARI 15 (early 2022 Update) * PLEASE PLEASE — If you are having trouble, and really want to get help or help others by posting a comment about it, Post Your Browser and Device (MacBook/IPad/etc… with both browser and OS version numbers!) Claiming none of these work is not accurate (and … Read more

Get the real width and height of an image with JavaScript? (in Safari/Chrome)

Webkit browsers set the height and width property after the image is loaded. Instead of using timeouts, I’d recommend using an image’s onload event. Here’s a quick example: var img = $(“img”)[0]; // Get my img elem var pic_real_width, pic_real_height; $(“<img/>”) // Make in memory copy of image to avoid css issues .attr(“src”, $(img).attr(“src”)) .load(function() … Read more

Flex / Grid layouts not working on button or fieldset elements

The Problem In some browsers the <button> element doesn’t accept changes to its display value, beyond switching between block and inline-block. This means that a <button> element cannot be a flex or grid container, or a <table>, either. In addition to <button> elements, you may find this constraint applying to <fieldset> and <legend> elements, as … Read more