dom-events

JavaScript “this” references wrong object [duplicate]

随声附和 提交于 2019-11-27 19:20:34
问题 This question already has an answer here: How to access the correct `this` inside a callback? 10 answers Well, this doesn't really refer to the wrong object, but I do not know how to refer to the correct one. function someObj() { this.someMethod1 = function() { var elementBtn = document.getElementById('myBtn'); elementBtn.onclick = function() { this.someMethod2(); //I want this.someMethod2() to be called //...but it tries to call elementBtn.someMethod2() i believe. }; }; this.someMethod2 =

Microsoft Surface: How do I allow JavaScript touch/drag events to work without being intercepted by the browser?

心已入冬 提交于 2019-11-27 18:45:18
问题 I have a Google Maps map on my web site, but when using it with a Microsoft Surface tablet, the "pan" gesture is intercepted by the browser -- it tries to go to the next browser window. How do I allow the pan (drag event) to be ignored by the browser so the map behaves normally? Going to maps.google.com , the map is perfectly dragable, so there must be a workaround that Google employs. 回答1: According to MS's guide on "Pointer and gesture events" (here: http://msdn.microsoft.com/en-us/library

trigger custom event without jQuery

白昼怎懂夜的黑 提交于 2019-11-27 17:30:48
问题 I'm triggering some DOM Events with jQuery triggerHandler() <!DOCTYPE html> <html> <head> <title>stackoverflow</title> <script src="http://ajax.googleapis.com:80/ajax/libs/jquery/2.1.3/jquery.min.js"></script> </head> <body> <script> $(document).ready(function() { $(document).on('hey', function(customEvent, originalEvent, data) { console.log(customEvent.type + ' ' + data.user); // hey stackoverflow }); // how to this in vanilla js $(document).triggerHandler('hey', [{}, { 'user':

Netflix video player in Chrome - how to seek?

久未见 提交于 2019-11-27 16:42:37
问题 I have been unable to figure out how to do a video seek (automatically advance to a certain point in the video) in the Netflix video player running in Chrome. The currentTime property can be read but not set in the Netflix player, and when set, immediately triggers the error "Whoops! Something went wrong.". Other actions such as Play and Pause work quite well. For example, you can try the following: Log into Netflix (from Google Chrome) and go to the movie Armageddon. After the movie loads,

Why is this JavaScript page redirect so slow?

天大地大妈咪最大 提交于 2019-11-27 16:21:02
I'm implementing a Firefox plugin. In the plugin's toolbar, I capture the current page and redirect users to the UK Google when they try to go to the Netherlands Google instead. However, this code takes forever to complete. When I type "google.nl" or "google.com/nl", my browser shows the Netherlands page and takes at least 1 second before redirecting. Is there any way to make the redirect faster? Ideally, I'd like the user to not see the Netherlands Google page at all. function loadURL(url) { window._content.document.location = url; window.content.focus(); } var redirected = false; function

keydown event new value

淺唱寂寞╮ 提交于 2019-11-27 16:18:33
问题 Browser: Google Chrome V19.0.1084.52 I have a textbox which needs to be a number less than or equal to 255, on keydown I want to check if this value is above or equal to 255 else prevent the event. In the Console when I console.log the event it will show event.srcElement.value as the value will appear i.e. from 12 => 123, when I console.log just event.srcElement.value it will show as the input was, not will be. Console.log's are happening one after the other, nothing in between, no pauses.

Can I change the context of javascript “this”?

百般思念 提交于 2019-11-27 15:37:40
问题 var UI$Contract$ddlForm_change = function() { //'this' is currently the drop down that fires the event // My question is can I change the context so "this" represents another object? this = SomeObject; // then call methods on the new "this" this.someMethod(someParam); }; is this possible? 回答1: No, it's not possible. You can call a method with a specified value for this (using method.apply() / method.call() ) but you cannot re-assign the keyword, this . 回答2: You can't change what this refers

Form not submitting when pressing enter

泄露秘密 提交于 2019-11-27 15:35:39
问题 I have the following HTML/JS/jQuery Code. This code represents a login form that is presented modally to the user to allow them to login. The problem is, when I hit enter, the form does not seem to execute the "onsubmit" event. When I click the button as the bottom of the form (which has virtually the same code as the onsubmit event), it works perfectly. I am wondering if anyone can tell me why this form isn't submitting..? Any assistance would be appreciated. jQuery Code to Show Login Modal:

Are events generated by Firefox extension 'trusted'?

吃可爱长大的小学妹 提交于 2019-11-27 15:12:40
My Firefox extension generates events, e.g. click. In response, the web application tries to open a new window. However it's getting blocked by Firefox as Popup blocker kicks in. However, if I manually click a button and in response to that when the web app tries to open window, it goes through. My question is why aren't events generated by my extension treated as 'trusted', and treated the same way at user click? Is there some backdoor to achieve that behavior? Edit : This answer is badly outdated. It refers to classic extensions that are no longer supported as of Firefox 57. Extensions based

How to to initialize keyboard event with given char/keycode in a Chrome extension?

风格不统一 提交于 2019-11-27 15:07:57
I'm developing a Google Chrome extension which simulates keyboard events on a web-page. I found that event.initKeyboardEvent() does not work properly because of this webkit bug and I also found some workarounds, e.g. SO Question However, defining properties on event object is not working because extension's content script has its own "parallel world" so properties defined in content script are not visible to web-page script. My only and last hope that DOM 4 Event Constructors work in Google Chrome and it would be possible to properly initialize keyboard event through constructor var event =