我正在尝试在窗口加载window.open
但它实际上并不起作用。我想这个问题是关于我如何管理我的onload功能,但我不明白这里的问题,我的console.log中没有显示任何内容(我没有错误)
我的HTML代码:
<html>
<head>
<script type="text/javascript" src="js/ftp.js"></script>
<script type="text/javascript" src="js/jquery-1.11.0.js"></script>
<title>FTPtoolJS</title>
</head>
<body bgcolor='#ffffff'>
<p><table border='0' cellpadding='0' cellspacing='1'
align='center' width='98%'>
<form name=login>
<tr><td align='right'> Username </td>
<td> <input type='text'
name='username' value='username' size='20'
maxlength='20'> </td></tr>
<tr><td align='right'> Password </td>
<td> <input type='text'
name='password' value='**********' size='20'
maxlength='20'> </td></tr>
<tr><td align='right'> Server </td>
<td> <input type='text'
name='server' value='ftp.adresse.com' size='60'
maxlength='120'> </td></tr>
<tr><td align='right'> Directory </td>
<td> <input type='text'
name='directory' size='60'
maxlength='200'> </td></tr>
</form>
</table><hr>
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td align='right'>
<input style='color:#000000' type='button' value='Connect' onClick='Login(this.form)'>
</td>
</tr>
</table>
</body>
</html>
我的JS代码:
function Login(form) {
var username = form.username.value;
var password = form.password.value;
var server = form.server.value;
var directory = form.directory.value;
if (username && password && server) {
FTPConnect(username, password, server, directory);
}
else {
alert("error");
}
}
function FTPConnect(username, password, server, directory){
var url;
var w;
if(directory != undefined){
url = "ftp://" + username + ":" + password + "@" + server + "/" + directory;
w = window.open("ftp://" + username + ":" + password + "@" + server + "/" + directory, '_blank',
'toolbar=yes,location=yes,status=yes,' +
'scrollbars=auto,copyhistory=no,menubar=no,width='
+ ((screen.AvailWidth/2)-12) + ',height='
+ (screen.AvailHeight-124) +',left=' + ((screen.AvailWidth/2))
+ '),top=0,resizable=yes');
}
else {
url = "ftp://" + username + ":" + password + "@" + server;
w = window.open("ftp://" + username + ":" + password + "@" + server, '_blank',
'toolbar=yes,location=yes,status=yes,' +
'scrollbars=auto,copyhistory=no,menubar=no,width='
+ ((screen.AvailWidth/2)-12) + ',height='
+ (screen.AvailHeight-124) +',left=' + ((screen.AvailWidth/2))
+ '),top=0,resizable=yes');
}
w.onload = function() {
console.log(w.documentElement.outerHTML); //here nothing is displayed in console.log
}
}
答案 0 :(得分:1)
快速浏览一下您的代码以及以下内容
w = window.open("ftp://" + username + ":" + password + "@" + ...
未通过same origin policy测试,因为
server
也可能是另一个主持人在这种情况下,您也无法通过 CORS 启用支持,因为访问 Window 比 XMLHttpRequest更严格因为它不会寻找许可标题。
它看起来像用户名&amp;密码不会使原点测试失败