I have two bookmarklets that work individually 1)
javascript:(function(){window.open("http://mail.yahoo.com");})();
2)
javascript:(function(){;document.getElementsByClassName('btn-compose')[0].click()})();
(the above lines of code were put through a bookmarklet generator here: http://ted.mielczarek.org/code/mozilla/bookmarklet.html and each bookmarklet works fine)
but when they are together like so: javascript:(function(){window.open("http://mail.yahoo.com");document.getElementsByClassName('btn-compose')[0].click()})();
or like so:
javascript:(function(){window.open("http://mail.yahoo.com");})();
javascript:(function(){;document.getElementsByClassName('btn-compose')[0].click()})();
the compose window does not open. I have a feeling the DOM is not ready.
but this fails:
javascript:(function(){window.open("http://mail.yahoo.com");})();
document.onreadystatechange = function () {
if (document.readyState == "complete") {
javascript:(function(){;document.getElementsByClassName('btn-compose')[0].click()})();
}
}
You have several issues going on.
window.open()
opens a new window. If you wanted to operate on that window, you would have to get that window handle and then get the document from THAT window. Right now, you're trying to operate on the original window with your second script.
A script launched from one window cannot access a different domain in a different window due to browser security restrictions.
It appears to me that you will either have to manually launch the second script after the Yahoo window opens. Or, you will need to use a browser plugin that can access the new window.
It also appears that you're trying to solve a problem that is probably already solved (bringing up a compose window in Yahoo mail). There is probably a URL you can just open in a new window that will start the compose window directly without having to hack into the window to push a button.
See this post for info on a URL that will take you to a Yahoo compose window. The general form of the URL is this: http://compose.mail.yahoo.com/?to=TO&subject=SUBJECT&body=BODY