dom-events

Checkbox Check Event Listener

陌路散爱 提交于 2019-12-17 08:18:07
问题 Recently I have been working with the Chrome Plugin API and I am looking to develop a plugin which will make life easier for me for managing a website. Now what I wish to do is to fire an event when a certain checkbox is checked. As this website does not belong to me I cannot change the code therefore I am using the Chrome API. One of the main problems is that rather than there being an ID, there is a Name. I was wondering if I could fire the function once the certain checkbox with the 'name'

Why inline JavaScript is bad?

*爱你&永不变心* 提交于 2019-12-17 07:31:35
问题 It is always recommended to avoid inline Javascript codes by putting all codes in a JS file, which is included in all pages. I wonder, if this does not cause performance problem in heavy pages. For example, imagine that we have tens of functions like this function function1(element){ var el=document.getElementsByClassName(element); var size=el.length; if(size==0) return; for(i=0;i<size;i++){ // the process } } on every page, we need to run the functions to know if there are corresponding

Why inline JavaScript is bad?

懵懂的女人 提交于 2019-12-17 07:31:27
问题 It is always recommended to avoid inline Javascript codes by putting all codes in a JS file, which is included in all pages. I wonder, if this does not cause performance problem in heavy pages. For example, imagine that we have tens of functions like this function function1(element){ var el=document.getElementsByClassName(element); var size=el.length; if(size==0) return; for(i=0;i<size;i++){ // the process } } on every page, we need to run the functions to know if there are corresponding

link element onload

断了今生、忘了曾经 提交于 2019-12-17 07:19:58
问题 Is there anyway to listen to the onload event for a <link> element? F.ex: var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'styles.css'; link.onload = link.onreadystatechange = function(e) { console.log(e); }; This works for <script> elements, but not <link> . Is there another way? I just need to know when the styles in the external stylesheet has applied to the DOM. Update: Would it be an idea to inject a hidden <iframe> , add the <link> to the head and listen

Looping through files for FileReader, output always contains last value from loop

烂漫一生 提交于 2019-12-17 07:07:10
问题 I'm using FileReader API to read files on local. <input type="file" id="filesx" name="filesx[]" onchange="readmultifiles(this.files)" multiple="" /> <script> function readmultifiles(files) { var ret = ""; var ul = document.querySelector("#bag>ul"); while (ul.hasChildNodes()) { ul.removeChild(ul.firstChild); } for (var i = 0; i < files.length; i++) //for multiple files { var f = files[i]; var name = files[i].name; alert(name); var reader = new FileReader(); reader.onload = function(e) { // get

onclick function runs automatically

大憨熊 提交于 2019-12-17 06:44:08
问题 Using google apps script I'm having trouble running a js function which passes parameters. When I add the parameters it will always run the code when the page loads instead of when the button is clicked. Direct from the HtmlService example, it is OK - it runs when the button is pressed... document.getElementById('button1').onclick = doSomething; But when I add a parameter to the call (and function) as below, it runs just once when the page loads (and not when the button is pressed)...

onclick function runs automatically

懵懂的女人 提交于 2019-12-17 06:44:00
问题 Using google apps script I'm having trouble running a js function which passes parameters. When I add the parameters it will always run the code when the page loads instead of when the button is clicked. Direct from the HtmlService example, it is OK - it runs when the button is pressed... document.getElementById('button1').onclick = doSomething; But when I add a parameter to the call (and function) as below, it runs just once when the page loads (and not when the button is pressed)...

Intercept all ajax calls?

放肆的年华 提交于 2019-12-17 04:53:56
问题 I'm trying to intercept all AJAX calls in order to check if that AJAX response contains specific error code that I send as JSON from my PHP script (codes: ACCESS_DENIED, SYSTEM_ERROR, NOT_FOUND). I know one can do something like this: $('.log').ajaxSuccess(function(e, xhr, settings) { }); But - does this work only if "ajaxSuccess" event bubble up to .log div? Am I correct? Can I achieve what I want by binding "ajaxSuccess" event to document? $(document).ajaxSuccess(function(e, xhr, settings)

How do I know when I've stopped scrolling?

故事扮演 提交于 2019-12-17 04:28:10
问题 How do I know when I've stopped scrolling using Javascript? 回答1: You can add an event handler for the scroll event and start a timeout. Something like: var timer = null; $(window).addEventListener('scroll', function() { if(timer !== null) { clearTimeout(timer); } timer = setTimeout(function() { // do something }, 150); }, false); This will start a timeout and wait 150ms. If a new scroll event occurred in the meantime, the timer is aborted and a new one is created. If not, the function will be

How do I know when I've stopped scrolling?

陌路散爱 提交于 2019-12-17 04:26:05
问题 How do I know when I've stopped scrolling using Javascript? 回答1: You can add an event handler for the scroll event and start a timeout. Something like: var timer = null; $(window).addEventListener('scroll', function() { if(timer !== null) { clearTimeout(timer); } timer = setTimeout(function() { // do something }, 150); }, false); This will start a timeout and wait 150ms. If a new scroll event occurred in the meantime, the timer is aborted and a new one is created. If not, the function will be