不能申请事件到另一个页面。
例如,您可以通过GET参数通过这个用户名:
window.location.replace("http://www.example.com/access/login/?username=" + "xxxx");
然后,在access/login/
页面,您可以使用服务器端语言插入此username
。例如,使用PHP:
<input type="text" id="username" name="username" value="<?php echo $_GET['username']; ?>"/>
JavaScript可以使用GET参数以及工作,但它是更好的主意,在服务器端做到这一点。如果你没有任何服务器端语言,你可以做到这一点使用JS:
var query = window.location.search.substr(1).split('=');
if (query.length === 0) return; // no username argument
if (query.length === 2 && query[0] === 'username') {
document.getElementById('username').value = query[1];
}
我的解决方案是绝对不是最好的一个,它只是举例提供。你可以用你的,更优雅和方便的方式做到这一点。
为什么你需要填充用户名? –
我需要与其他人分享我的用户名和密码 – user252718