dom-events

Why onbeforeunload event is not firing

余生颓废 提交于 2020-01-01 19:44:35
问题 I tried the code on Chrome, FireFox and Safari. Still the onbeforeunload does not fire. I also tried the onunload , but it did not work. Here is the code I am experimenting with: <!doctype html> <html lang="en"> <head> <title> Output to a Page </title> <meta charset="utf-8"> <script> window.onload = init; window.onclick = clk; window.onbeforeunload = closing; function clk() { window.alert("Ouch !!"); } function closing() { console.log("function alrt WORKS !!!!"); window.alert("closing now....

How can I get x and y number at every click event on Google Maps?

孤人 提交于 2020-01-01 11:26:19
问题 I want to retrieve x/y coordinates at every click-event on Google Maps. Could someone help me please? 回答1: google.maps.event.addListener(map, "click", function (e) { document.form1.waypointLog.value = e.latLng.lat().toFixed(6) + ' |' + e.latLng.lng().toFixed(6); }); Source: https://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/3f4329e3a20e7b0b You can also check: http://forums.gpsreview.net/viewtopic.php?t=3632 来源: https://stackoverflow.com/questions/8766116/how-can-i-get

Javascript Event for “Open in new Tab”

﹥>﹥吖頭↗ 提交于 2020-01-01 09:17:10
问题 I have the following problem: I use Javascript onclick event to change href of a link. It works like a charm but only if user just clicks a link. If "Open in new tab" feature is used for the link - onclick event will not fire and href will never change. Is there any way to handle such an event? Perhaps with jQuery or some other JS Framework? Example: <a href="some_url" onclick="this.href = 'some_other_url'">Link</a> 回答1: Try to change <a href="some_url" onclick="this.href = 'some_other_url'"

Prototype - click event by element class name

别说谁变了你拦得住时间么 提交于 2020-01-01 04:24:29
问题 I am new to the prototype framework and am trying something really simple and failing. I am trying to respond to a click event on a button like so: $$('.btn').observe('click', respond); function respond(event) { alert("hello"); } Why isn't this working? Please help! 回答1: Unlike jQuery, handing selectors with multiple results in Prototype works a little differently. You need to handle each selected result separately using .each() . $$('.btn').each(function(element) { element.observe('click',

Which key does the e.metaKey refer to in JavaScript MouseEvent?

偶尔善良 提交于 2020-01-01 04:20:13
问题 MouseEvent.metaKey doesn't seem to work. On both FireFox and Chrome, it returns false even if I hold the Win key while clicking: <!doctype html> <button onclick=alert(event.metaKey)>click while holding "meta key"</button> MDN states: The MouseEvent.metaKey read-only property returning a Boolean that indicates if the Meta key was pressed ( true ) or not ( false ) when the event occured. Note: On Macintosh keyboards, this is the command key ( ⌘ ). On Windows keyboards, this is the windows key (

Ionic 2 Events, publish and subscribe not working

我的未来我决定 提交于 2019-12-30 18:50:29
问题 I'm trying to use Publish and Subscribe from ionic-angular But I am not receiving any data nor error. Here are my codes Page 1 import {Events} from 'ionic-angular' static get parameters(){ return [[Events]]; } constructor(Events) { this.events = Events; this.events.publish("Msg", "Hello World"); } Page 2 import {Events} from 'ionic-angular' static get parameters(){ return [[Events]]; } constructor(Events) { this.events = Events; this.events.subscribe("Msg", (data) => { console.log(data[0]); }

Listen for jQuery Event With Vanilla JS

泪湿孤枕 提交于 2019-12-30 18:26:16
问题 So I am trying to determine whether its possible to listen for events added with jQuery using vanilla JS. I found this question: Listen to jQuery event without jQuery which definitely answers it for version 1 of jQuery. How about version 3 however? I have a fiddle that I have put together to test out, but I am unable to get the 1st submit to work with any version of jQuery. Am I missing something, or is the event model in jQuery 3 still not using the DOM event model? https://jsfiddle.net

window.location.href doesn't redirect

穿精又带淫゛_ 提交于 2019-12-30 07:54:14
问题 I know this is a question much discussed but I can't figure out why it does not work for me. This is my function: function ShowComments(){ alert("fired"); var movieShareId = document.getElementById('movieId'); //alert("found div" + movieShareId.textContent || movieShareId.innerText); //alert("redirect location: /comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/"); window.location.href = "/comments.aspx?id=" + movieShareId.textContent || movieShareId.innerText + "/";

How to change the value of a check box onClick using JQuery?

折月煮酒 提交于 2019-12-30 06:17:07
问题 Here I am trying to change the value of the following check box while clicking on it. In the code below I tried to change the value of the checkbox to 1 and change the value to 0 when unchecked. But it takes only the false condition, when the checkbox is unchecked the value changes to 0 but when checked its not changing to 1. Any suggestions how to fix this out ? <input type="checkbox" id="read" name="permission[]" onClick="($(this).checked)?$(this).attr('value',1):$(this).attr('value',0)"/>

What are the best light-weight solutions for Drag and Drop?

拜拜、爱过 提交于 2019-12-30 03:29:05
问题 I love and use jQuery quite a lot, but I am hoping to find an alternate solution for a special project. I am creating a bookmarklet which will interface with my application to allow users to enter information much quicker. One of the greatest pains in my application at the moment is uploading images. Users (understandly) hate the process of downloading images to their computers in an organized fashion, and then uploading them to the app. What I would love the bookmarklet to do is load in a