I would like to open a new tab with posting some data to that tab. How can I do this ?
Thank in advance for your help.
You could create a form, and submit it via JavaScript. A general example can be found here. This can be done from anywhere within your extension, ranging from the background page to content scripts.
If you need more control over the location of the form without content scripts, you can use data-URLs, with the following generic format:
data:text/html;charset=utf8,
Or, programatically:
var url = 'data:text/html;charset=utf8,';
function append(key, value) {
var input = document.createElement('textarea');
input.setAttribute('name', key);
input.textContent = value;
form.appendChild(input);
}
var form = document.createElement('form');
form.method = 'POST';
form.action = 'http://rob.lekensteyn.nl/dump.php';
append('q', 'query');
url += encodeURIComponent(form.outerHTML);
url += encodeURIComponent('');
// A general method
window.open(url);
// Or, use chrome extension-specific method which offers more control
// chrome.tabs.create({url: url, active: true});
PS. Source code of http://rob.lekensteyn.nl/dump.php (used to show headers and POST data):
$value) {
if (strpos($header, 'HTTP_') === 0) {
echo str_pad(substr($header, 5), 20) . " " . $value . "\n";
}
}
echo "\n\n";
$input = fopen('php://input', 'rb');
while (!feof($input)) {
echo fread($input, 102400);
}
fclose($input);
?>