所以我正在尝试用chrome做一个书签,它会输入一个Javascript代码,用来填满我路由器主页上的一个文本框。这样做的目的是让我省去记住那个愚蠢的密码或者打开包含该密码的文本文件的麻烦。
我知道我知道。我很懒。(但不是为了在这个过程中学习一些Javascript )
问题是textbox没有ID,而且它的名称在重新加载时会发生变化,所以我不能提前知道它的名称。
我已经看了这里的一些页面,这类指导我在正确的方向,但我不能让它为我的生活,因为我几乎没有经验的Javascript。
文本框的html如下所示:
<input type="PASSWORD" style="WIDTH: 150px" name="password_random10digitnumber" value="" size="20" maxlength="64">
这是我在我的书签上得到的一个链接(我尝试过的唯一一件事没有给我一个错误)。
javascript:document.getElementsByTagName("input").value='myrouterpwd‘
目前,当我按下我的书签时,它会刷新页面,并显示一个带有"myrouterpwd“的空白页面。
(页面上还有另外两个输入html块,它们是:
<input type="HIDDEN" name="md5_pass" value="">
<input type="HIDDEN" name="auth_key" value="numbersIamnotsureIshouldshowtheworld">
)
感谢所有愿意花时间回答的人!
发布于 2018-09-11 08:21:25
我没有太多使用书签的经验,我假设因为它是一个书签,所以你正在远离你真正想要使用的页面。所以,我不确定以这种方式触发它是一个可行的解决方案。当然,您也可以利用浏览器为您存储密码的功能。;)
但是,就你的问题的要点而言...假设它是页面上唯一的密码字段,使用element.querySelector()
将会找到它:
// Get a reference to the right element based on its type attribute value
let passwordBox = document.querySelector("input[type='password']");
passwordBox.value = "MySecretPassword"; // Populate the field
console.log(passwordBox.value); // Confirmation
[type='password'] { background:yellow; } /* Just so you know which box is the password box */
<input type="hidden" name="doesntMatter">
<input name="someTextBox">
<input type="password" name="doesntMatter2">
<input name="someOtherTextbox">
https://stackoverflow.com/questions/52267033
复制相似问题