javascript - Get originalTarget from tab load event MDN -
i'm trying originaltarget dom following example :
gbrowser.addeventlistener("load", function(aevent){ s.handleloadbrowser(aevent);}, true); handleloadbrowser : function (aevent){ var w = aevent.originaltarget.defaultview; }
i create event listener tab load:
var tab = gbrowser.addtab("www.google.com"); tab.addeventlistener("load", function(aevent){ s.handleloadtab(aevent) }, true); handleloadtab : function (aevent){ var w = aevent.originaltarget.defaultview; }
here error: "typeerror: win undefined".
how dom object tab event load ?
regarding first example, should work: did similar: https://gist.github.com/noitidart/9287185#file-bootstrap-js-l98 difference do: gbrowser.addeventlistener("load", s.handleloadbrowser, true);
regarding second example: var tab = gbrowser.addtab("www.google.com"); tab.addeventlistener("load", function(aevent){ s.handleloadtab(aevent) }, true);
cant this, dont add load events tab, tab xul element grab , move around. can tab.linkedbrowser.contentwindow.addeventlistener('load'
after first page load no longer there.
this code works me:
var tab = gbrowser.addtab("data:text/html,<b>hi</b>"); tab.linkedbrowser.contentwindow.addeventlistener("load", handleloadtab, true); //tab.linkedbrowser.contentwindow.addeventlistener("domcontentloaded", handleloadtab, true); function handleloadtab(aevent){ var w = aevent.originaltarget.defaultview; w.alert('load done') }
also here's example of how listen first on load of 1 tab. use gbrowser.loadonetab
in example, interchangeable addtab
: https://gist.github.com/noitidart/0f076070bc77abd5e406
var tab = gbrowser.loadonetab('data:text/html,<span class="profilist-build-icon-1">backround of span of icon on desktop</span><input type="button" value="applycss"><input type="button" value="removecss"> change file on desktop to: <input type="button" value="release img"><input type="button" value="beta img"><input type="button" value="aurora img"><input type="button" value="nightly img">', {inbackground:false}); var mobs = new window.mutationobserver(function(mutations) { mutations.foreach(function(mutation) { var attrval = tab.getattribute(mutation.attributename); console.log(mutation.attributename, attrval); if (mutation.attributename == 'progress' && attrval == 'true') { //at point can addeventlistener domconentloaded , document hasnt loaded yet tab.linkedbrowser.contentdocument.addeventlistener('domcontentloaded', function() { tab.linkedbrowser.contentdocument.removeeventlistener('domcontentloaded', arguments.callee, false); alert('loadonetab finished loading', tab.linkedbrowser.contentdocument.body.innerhtml) }, false); mobs.disconnect(); } /* if (mutation.attributename == 'progress' && attrval == '') { //cannot add addeventlistener domconentloaded here document loaded, never fire alert('tab done loading'); mobs.disconnect(); } */ }); }); mobs.observe(tab, { attributes: true }); console.log(tab._fullyopen)
Comments
Post a Comment