我有这样的问题。我是javascript的新手。我必须登录第三方资源。在重定向网址中登录此资源检索参数后。我需要获取此参数并将其传递给servlet。我可以在弹出窗口中打开登录窗口,但是如何从中重定向url获取参数,将其传递给servlet,更新父页面并在我登录时关闭弹出窗口。我的代码:
var signinWin;
var w = 780;
var h = 410;
$(document).ready(function() {
$('#popupButton').click(function() {
signinWin = popupwindow([my url],
"SignIn",960,630);
signinWin.focus();
var code = getQueryVariable("code");
console.log(code);
if(code != null){
signinWin.close();
}
return false;
signinWin.opener.location.reload(true);
});
});
function popupwindow(url, title, w, h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
function getQueryVariable(variable) {
var query = signinWin.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
但它并不具备核心作用。重新加载父页面也不起作用。请帮忙