dhtml

Alternative to DOMNodeInserted

白昼怎懂夜的黑 提交于 2019-11-26 11:55:32
问题 DOMNodeInserted is known to make dynamic pages slow, MDN even recommends not using it altogether, but doesn\'t provide any alternatives. I\'m not interested in the element inserted, I just need to know when some script modifies the DOM. Is there a better alternative to mutation event listeners (maybe getElementsByTagName inside an nsiTimer)? 回答1: If you are creating a web app that targets recent mobile phones and newer versions of browsers (Firefox 5+, Chrome 4+, Safari 4+, iOS Safari 3+,

Capture iframe load complete event

偶尔善良 提交于 2019-11-26 11:42:41
Is there a way to capture when the contents of an iframe have fully loaded from the parent page? gblazex <iframe> elements have a load event for that. How you listen to that event is up to you, but generally the best way is to: 1) create your iframe programatically It makes sure your load listener is always called by attaching it before the iframe starts loading. <script> var iframe = document.createElement('iframe'); iframe.onload = function() { alert('myframe is loaded'); }; // before setting 'src' iframe.src = '...'; document.body.appendChild(iframe); // add it to wherever you need it in

Child element click event trigger the parent click event

主宰稳场 提交于 2019-11-26 09:40:38
问题 Say you have some code like this: <html> <head> </head> <body> <div id=\"parentDiv\" onclick=\"alert(\'parentDiv\');\"> <div id=\"childDiv\" onclick=\"alert(\'childDiv\');\"> </div> </div> </body> </html>​ I don\'t want to trigger the parentDiv click event when I click on the childDiv , How can I do this? Updated Also, what is the execution sequence of these two event? 回答1: You need to use event.stopPropagation() Live Demo $('#childDiv').click(function(event){ event.stopPropagation(); alert

jQuery: how to change tag name?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 08:13:59
问题 jQuery: how to change tag name? For example: <tr> $1 </tr> I need <div> $1 </div> Yes, I can Create DOM element <div> Copy tr content to div Remove tr from dom But can I make it directly? PS: $(tr).get(0).tagName = \"div\"; results in DOMException . 回答1: You can replace any HTML markup by using jQuery's .replaceWith() method. example: http://jsfiddle.net/JHmaV/ Ref.: .replaceWith If you want to keep the existing markup, you could use code like this: $('#target').replaceWith('<newTag>' + $('

Print <div id=“printarea”></div> only?

限于喜欢 提交于 2019-11-26 05:40:37
问题 How do I print the indicated div (without manually disabling all other content on the page)? I want to avoid a new preview dialog, so creating a new window with this content is not useful. The page contains a couple of tables, one of them contains the div I want to print - the table is styled with visual styles for the web, that should not show in print. 回答1: Here is a general solution, using CSS only , which I have verified to work. @media print { body * { visibility: hidden; } #section-to

Capture iframe load complete event

孤者浪人 提交于 2019-11-26 02:19:13
问题 Is there a way to capture when the contents of an iframe have fully loaded from the parent page? 回答1: <iframe> elements have a load event for that. How you listen to that event is up to you, but generally the best way is to: 1) create your iframe programatically It makes sure your load listener is always called by attaching it before the iframe starts loading. <script> var iframe = document.createElement('iframe'); iframe.onload = function() { alert('myframe is loaded'); }; // before setting

getElementsByTagName() equivalent for textNodes

ぃ、小莉子 提交于 2019-11-26 01:23:59
问题 Is there any way to get the collection of all textNode objects within a document? getElementsByTagName() works great for Elements, but textNode s are not Elements. Update: I realize this can be accomplished by walking the DOM - as many below suggest. I know how to write a DOM-walker function that looks at every node in the document. I was hoping there was some browser-native way to do it. After all it\'s a little strange that I can get all the <input> s with a single built-in call, but not

Cross-platform, cross-browser way to play sound from Javascript?

梦想与她 提交于 2019-11-26 00:27:48
问题 I am writing a dhtml application that creates an interactive simulation of a system. The data for the simulation is generated from another tool, and there is already a very large amount of legacy data. Some steps in the simulation require that we play \"voice-over\" clips of audio. I\'ve been unable to find an easy way to accomplish this across multiple browsers. Soundmanager2 comes pretty close to what I need, but it will only play mp3 files, and the legacy data may contain some .wav files

Redirect parent window from an iframe action

戏子无情 提交于 2019-11-25 23:52:54
问题 What JavaScript do I need to use to redirect a parent window from an iframe? I want them to click a hyperlink which, using JavaScript or any other method, would redirect the parent window to a new URL. 回答1: window.top.location.href = "http://www.example.com"; As stated previously, will redirect the parent iframe. 回答2: I found that <a href="..." target="_top">link</a> works too 回答3: window.top.location.href = "http://example.com"; window.top refers to the window object of the page at the top

jQuery document.createElement equivalent?

∥☆過路亽.° 提交于 2019-11-25 22:42:53
问题 I\'m refactoring some old JavaScript code and there\'s a lot of DOM manipulation going on. var d = document; var odv = d.createElement(\"div\"); odv.style.display = \"none\"; this.OuterDiv = odv; var t = d.createElement(\"table\"); t.cellSpacing = 0; t.className = \"text\"; odv.appendChild(t); I would like to know if there is a better way to do this using jQuery. I\'ve been experimenting with: var odv = $.create(\"div\"); $.append(odv); // And many more But I\'m not sure if this is any better