Javascript submit() event is not fired up on exit (unload event)

I got page where HTML elements <form> and <iframe> are dinamicaly created with Javascript:

document.write('<iframe id="myIframe" name="myIframe" src="about:blank" style="display:none;"></iframe>');
document.write('<form id="myForm" name="myForm" method="post" target="myIframe" action="myURL.php" style="display:none;">');
document.write('<textarea name="d"></textarea>');

Then some data is placed into <textarea> element and submited:

var data = '';

function myOnClick()
    // combine data
    data += 'click|';

    if (data.length > 17)
        // initiate after 3rd click
function myOnUnload()
    if (data.length > 0)
function mySubmit()
    var form     = document.getElementById('myForm');
    var textarea = form.getElementsByTagName('textarea')[0];

    // set data
    textarea.innerHTML = data;
    // send data

    // set var to default value
    data = '';

if (document.addEventListener)
    // Gecko browsers
    document.addEventListener('mousedown', myOnClick, false);
else if (document.attachEvent)
    // IE browsers
    document.attachEvent('onmousedown', myOnClick, false);

window.onunload = function()

The problem is that clicking on the page data is combined and sent as it supose to do on both Gecko and IE browsers in the same way. But when user is leaving the page and the data is set form.submit() is not initiated on Gecko browser though IE does it as I wanted to do.

For example, on the same page exists link <a href="">Google</a> which user submits after he/she clicked anywhere on the page. Once user done that, data is set and need to be submited to myURL.php, but it's not.

UPDATE: This is the whole code By mentioning Gecko based browsers I had in mind other popular browsers such as Firefox, Opera, Chrome and Safari. Sorry for misleading.

What could be the problem: Javascript code, browser behaviour or something else?


This MS Article could help with your issue.

Not sure if that is your exact problem without seeing more of your code. If that is all of your code, it is very likely that is the problem.

Need Your Help

Should I ever need to call RTRIM() on a varchar or nvarchar value?

sql sql-server tsql

I believe the answer to this question is "no" but I'm interested in the community opinion. A varchar or nvarchar value should automatically trim trailing whitespace, so I don't believe I should eve...

feature mobile phone tracking application

python security mobile

I would like to build a mobile phone tracking application for feature phones which have minimum of gprs connectivity. I would like a user to log in to the application and be able to see the locatio...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.