dom-events

How to detect on-page 404 errors using JavaScript?

吃可爱长大的小学妹 提交于 2019-11-28 19:20:34
I have an HTML page where several JavaScript, CSS and images files are referenced. These references are dynamically injected and user can manually copy the HTML page and the support files to another machine. If some JS or CSS are missing, the browser complains in the console. For example: Error GET file:///E:/SSC_Temp/html_005/temp/Support/jquery.js I need somehow these errors reported back to me on the inline JavaScript of the HTML page so I can ask user to first verify that support files are copied correctly. There's the window.onerror event which just inform me that there's a JS error on

How to detect when an image has finished rendering in the browser (i.e. painted)?

喜你入骨 提交于 2019-11-28 19:12:15
On a web app I need to work with a lot of high-res images, which are dynamically added to the DOM tree. They are pre-loaded, then added to the page. It's one thing to detect when such an image has finished loading, for this I use the load event, but how can I detect when it has finished being rendered within the browser, using Javascript? When working with high resolution images, the actual painting process can take a lot of time and it's very important to know when it ends. I used requestAnimationFrame to do the trick. After image loaded it will be rendered during the next animation frame. So

Text in HTML Field to disappear when clicked?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 18:37:12
I can easily create a html input field that has text already in it. But when the user clicks on the input field the text doesn't disappears but stays there. The user then has to manually remove the text to type. How can I create an input field where when the user clicks on the input field box the text then disappear? Nayish What you want to do is use the HTML5 attribute placeholder which lets you set a default value for your input box: <input type="text" name="inputBox" placeholder="enter your text here"> This should achieve what you're looking for. However, be careful because the placeholder

Javascript / jQuery or something to change text every some seconds

强颜欢笑 提交于 2019-11-28 18:24:46
Need JavaScript or jQuery something to change text every some seconds... with user doing anything. Example: "Welcome" changes to "Salmat datang" changes to "Namaste" etc after 3 secs and loops back. Thomas Shields As others have said, setInterval is your friend: var text = ["Welcome", "Hi", "Sup dude"]; var counter = 0; var elem = document.getElementById("changeText"); var inst = setInterval(change, 1000); function change() { elem.innerHTML = text[counter]; counter++; if (counter >= text.length) { counter = 0; // clearInterval(inst); // uncomment this if you want to stop refreshing after one

How do I listen for triple clicks in JavaScript?

徘徊边缘 提交于 2019-11-28 17:45:59
If this is for a double-click: window.addEventListener("dblclick", function(event) { }, false); How can I capture a triple-click? This is for a pinned tab in Google Chrome. You need to write your own triple-click implementation because no native event exists to capture 3 clicks in a row. Fortunately, modern browsers have event.detail , which the MDN documentation describes as : A count of consecutive clicks that happened in a short amount of time, incremented by one. This means you can simply check the value of this property and see if it is 3 : window.addEventListener('click', function (evt)

Firefox extension to find out which Javascript event is bound to an inspected element?

风格不统一 提交于 2019-11-28 17:04:22
问题 One can bind Javascript events to html elements without using inline declarations. Is there a way when inspecting an html element to know which events are bound to the element? I want to know about the events defined by the developer and not the internal ones that come with the browser. So if I hover over an element and a menu shows up, I want to know which method caused it. I have been trying Event Spy with the Code inspector but it logs too many of the internal ones, unless I am not using

Multiple JS event handlers on single element

本秂侑毒 提交于 2019-11-28 16:52:36
I am working with an existing web app, in the app there are a variety of submit buttons on different forms, some using regular http post, some defining an onClick function, and some binding a js event handler to the button using a class on the element. What I want to do, is bind another event handler to these buttons by just adding a class to the buttons, but what I want to determine is will the new event handler be guaranteed to be executed, or could one of the form submit actions happen before it does meaning my new function isn't hit. The example scenario is I want to add a class to these

Flashing between page loads

懵懂的女人 提交于 2019-11-28 16:52:32
问题 On a website, I'm experiencing a "flash" of white that occurs between page loads. It looks bad because I'm using a background image and when the page loads, the background images flash before it comes onto the screen (take a look for yourself). This issues occurs in chrome and IE but not in firefox. The site has a way of preloading stuff. Every element on the page is in a div wrapper #website which is initially at display:none , and every image is in a div wrapper #website-images which is

Get ID of element that called a function

不想你离开。 提交于 2019-11-28 16:40:00
问题 How can I get the ID of an element that called a JS function? body.jpg is an image of a dog as the user points his/her mouse around the screen at different parts of the body an enlarged image is shown. The ID of the area element is identical to the image filename minus the folder and extension. <div> <img src="images/body.jpg" usemap="#anatomy"/> </div> <map name="anatomy"> <area id="nose" shape="rect" coords="280,240,330,275" onmouseover="zoom()"/> </map> <script type="text/javascript">

Click source in JavaScript and jQuery, human or automated?

拥有回忆 提交于 2019-11-28 14:03:57
We all know that you can simulate click or any other event on an element using one of these ways: $('#targetElement').trigger('eventName'); $('#targetElement').click(); I have encountered a situation in which, I should know how an element is clicked. I should know if it's been clicked automatically via code, or by pressing mouse button. Is there anyway I can do it without hacks or workarounds? I mean, is there anything built into browsers' event object, JavaScript, or jQuery that can tell us whether click has been initiated by a human action or by code? Try this: $('#targetElement').click