if(e.getNewResourceLocation().equals("http://www.weibo.com/")) {
String script = "function getuser(){"
+ LS
+ "sendNSCommand('getuser',document.getElementsByName('username')[0].value,document.getElementsByName('password')[0].value);"
+ LS
+ "void(0);"
+ LS
+ "}"
+ LS
+ "document.getElementById('pl_login_form').getElementsByTagName('div')[10].getElementsByTagName('a')[0].href=\"javascript:'getuser()'\";"
+ "document.getElementById('pl_login_form').getElementsByTagName('div')[10].getElementsByTagName('a')[0].attachEvent('onclick',getuser);"
+ "alert('请登录!');";
webBrowser.executeJavascript(script);
}
/**
* 浏览器地址监控
*/
class GetuserListener extends WebBrowserAdapter {
@Override
public void commandReceived(WebBrowserCommandEvent e) {
String command = e.getCommand();
Object[] parameters = e.getParameters();
if ("print".equals(command)) {
String html = (String) parameters[0];
System.out.println(html);
}
if ("getuser".equals(command)) {
//获得登录的用户名 密码
Weibo.userName = (String) parameters[0];
Weibo.userPwd = (String) parameters[1];
}
}
}