I don't have a reference to any particular specification to support the why, but I believe it will work if you append the new form to the page:
$('button.search').live('click', function(event) {
jQuery('<form>', {
'action': 'http://www.google.com/search',
'target': '_top'
}).append(jQuery('<input>', {
'name': 'q',
'value': 'stack overflow',
'type': 'hidden'
})).appendTo('body')
.submit();
});
Note also that it would be a good idea not to keep using .live()
in any new code, given that it has been removed from the latest version of jQuery. Instead use:
$(document).on('click', 'button.search', function() { // in jQuery v 1.7+
// or
$(document).delegate('button.search', 'click', function() { // in jQuery v 1.4.3+
(Ideally specifying a parent element closer to the button rather than document
.)