Most likely impossible ...
Most likely, this will not be possible because the hosts between your local and remote will be different, so JavaScript will not allow you to access the contents of the iframe due to the Same origin policy that all browsers use.
http://en.wikipedia.org/wiki/Same_origin_policy
The only way to achieve this is if the other site does not use XSS protection and allows you to directly receive / send the login URL to your site. It really depends on who controls that ... if you own and control a local and remote site, then it will be possible. If this is not the case, it is unlikely and will be subject to various possible problems (i.e., if the remote site changes the way the login system works, the system will be broken, or it will not be possible to obtain fine-grained control over the login process, so you wonβt be able to implement your own error handling).
I assume that I say you should not rely on the XSS vulnerability.
Why is this protection protected from?
If you think about it, if there was no truth above, then there would be many very strong and scary things that evil people could do in the background while you were surfing the site. For example, if you could use JavaScript to exchange data between nodes in a hidden iframe, there would be nothing to stop someone encoding a hidden script that went to facebook, relied on your browser, saved your username and password, entered system, and then started publishing / deleting / making friends ... (and this is just a mild example that does not include credit card details or government sites)
Other options?
It is best to implement something in this direction - use a server-side scripting language, such as php, asp, java, node.js, ruby, lisp, perl or python. Scripting languages ββdo not have restrictions on working with external resources. Again, as long as the external site supports a simple or open login system, you should be able to mount something together, and not allow your JavaScript to register using the server side of the script as a proxy through AJAX. For example, you can use cURL via PHP to send to an external site and receive the cookies that it returns. However, this is not an easy project, and it will take a lot of work to work without problems.