Reputation: 103
I have been trying to get at the portion of a gmail screen where you actually write a message (I want to make a tiny chrome extension that will transposed mistyped characters).
But I find myself lost in a maze of little twisty iframes, all alike. I simply cannot produce a jquery expression that will fight its way through about 20 layers of nested divs to find the compose window. Even when I pick the id of the form out of the javascript inspector, it doesn't seem to be found by jquery.
Can anyone help?
Upvotes: 0
Views: 1194
Reputation: 19
This can be done by using popup javascript. When the page is loading insert a script into the compose window like this
window.onload = function () {
chrome.windows.getCurrent(function (currentWindow) {
chrome.tabs.query({ active: true, windowId: currentWindow.id },
function (activeTabs) {
chrome.tabs.executeScript(
activeTabs[0].id, { file: 'ExtractGmail.js', allFrames: true });
});
});
}
now in extractgmail.js what you have to do is extract the fields as defined below
var Email = document.getElementsByName("to")[0].value;
var Subject = document.getElementsByName("subject")[0].value;
var iframe = document.getElementsByClassName('Am Al editable')[0];
var content = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
var items = new Array();
items[0] = Email;
items[1] = Subject;
var body = content.body.innerHTML;
//content.body.innerHTML = body;
items[2] = body;
now from here you have all the fields you want. This is done and tested in previous version of gmail compose now as gmail has changed there compose UI i am working on it to do the same and will let you know if you need it
Upvotes: 0
Reputation: 14197
Not much need of jquery, but here's the link to open a gmail window:
https://mail.google.com/mail/?view=cm&fs=1&tf=1&su=Newest%20Questions%20-%20Stack%20Overflow&body=http%3A//stackoverflow.com/questions
With parameters:
- su: subject of the email
- body: body of the email
- view=cm: compose window
Also, other parameters would be:
"&to=", "&cc=", "&su=" and "&body="
Upvotes: 3