The workflow requested by customer is something like this :
The user on registration form clicks a button, opening another window:
$ ->
$("a.popup").on 'click', (e) ->
e.preventDefault()
newWindowCenter($(this).attr("href"), $(this).attr("data_width"), $(this).attr("data_height"), "authPopup")
where
newWindowCenter = (url, width, height, name) ->
left = (screen.width / 2) - (parseInt(width) / 2);
top = (screen.height / 2) - (parseInt(height) / 2);
window.addEventListener("dataAvailable", transferAccountData, false)
window.open(url, name,
"menubar=no,toolbar=no,status=no,width="+width+",height="+height+",alwaysRaise=yes,toolbar=no,left="+left+",top="+top)
In this new window he’s got some data, usage of which he confirms by clicking a button, so:
$(".confirm_data_usage").on 'click', (e) ->
e.preventDefault()
if (window.opener)
accountData= {...}
data = {...} #collected in opened window
approveDataTransfer = document.createEvent("Events")
approveDataTransfer.dataTransfer = data
approveDataTransfer.initEvent("dataAvailable", true, false)
approveDataTransfer.eventType = "data available"
window.opener.dispatchEvent(approveDataTransfer)
window.close()
So after clicking the ‘confirm_data_usage’ button the function inserting this data is fired in opener window
transferAccountData = (event) ->
data = event.dataTransfer
...
Thing is: it is working in Chrome and Opera, but in Firefox event.dataTransfer is undefined. Anyone sees an obvious mistake / knows something specific in Firefox preventing event from transferring data ? Maybe there is another way ? Could the problem be related to isTrusted attribute on approveDataTransfer event?
I’m not sure what’s going on with your event data but the way I usually handle this sort of thing is to attach a function to
window:And then in the new window, you can call that function directly through
window.opener:I haven’t had any problems with this approach in any browser.