dialog_popup.js | |
---|---|
/*jshint indent:2 */
/*global chrome:true */ | |
This listener reacts on the 'send_postdata' message, it generates a form for the citation-popup and submits it to the corresponding endpoint | (function () {
'use strict';
var onMessage, port, createSubmit; |
creating form, append this to the document and triggering submit | createSubmit = function (url, params) {
var form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', url);
form.setAttribute('enctype', 'application/x-www-form-urlencoded');
params.source = 'website';
var hiddenField = document.createElement('input');
hiddenField.setAttribute('type', 'hidden');
hiddenField.setAttribute('name', 'data');
hiddenField.setAttribute('value', encodeURIComponent(JSON.stringify(params)));
form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();
}; |
listener that reacts to a message that popped out the messageQueue in background.js | onMessage = function (request, sender, sendResponse) {
if (request.type === 'send_postdata') {
createSubmit(request.url, request.params);
}
};
chrome.extension.onMessage.addListener(onMessage);
}());
|