我知道如何将项目添加到 ie 右键单击菜单,但如何获取当前页面的元素?
I know how to add an item to ie right click menu, but how to get current page's element?
如何添加item到即右键菜单:
run cmd -> HKEY_CURRENT_USER -> Software -> Microsoft -> Internet Explorer -> MenuExt -> New an Item, Then set
the Default's value with a file's path (for example: D:\test.html)
但是,我想在D:\test.html中获取当前页面用户的用户名和电话,我可以打开一个新标签,这个新标签有用户名和电话,所以我可以打印打印机的用户名和电话
下面D:\test.html中的代码无法运行,你知道我想做什么:-):
<html>
<body>
</body>
<script>
alert(document.getElementById("hello").value);
</script>
</html>
下面是右击的页面
<html>
<body>
<div id="hello">hello, Whosebug!</div>
</body>
</html>
然后我运行它,像这样:
enter image description here
但是报错:
enter image description here
-------------------------------------------- --------------
这个问题已经解决,下面的html页面就是我想要的。书签是合适的方法。
enter image description here
脚本无法运行,因为它无法获取另一个页面中元素的值。脚本在page1,元素在page2,所以获取不到元素
在您的情况下,您应该使用 bookmarklet 而不是 IE 菜单。在您的小书签中使用以下脚本获取元素值:
javascript: (function () { alert(document.getElementById("hello").value); })();
使用以下步骤添加小书签:
如何添加item到即右键菜单:
run cmd -> HKEY_CURRENT_USER -> Software -> Microsoft -> Internet Explorer -> MenuExt -> New an Item, Then set
the Default's value with a file's path (for example: D:\test.html)
但是,我想在D:\test.html中获取当前页面用户的用户名和电话,我可以打开一个新标签,这个新标签有用户名和电话,所以我可以打印打印机的用户名和电话
下面D:\test.html中的代码无法运行,你知道我想做什么:-):
<html>
<body>
</body>
<script>
alert(document.getElementById("hello").value);
</script>
</html>
下面是右击的页面
<html>
<body>
<div id="hello">hello, Whosebug!</div>
</body>
</html>
然后我运行它,像这样: enter image description here
但是报错: enter image description here
-------------------------------------------- --------------
这个问题已经解决,下面的html页面就是我想要的。书签是合适的方法。 enter image description here
脚本无法运行,因为它无法获取另一个页面中元素的值。脚本在page1,元素在page2,所以获取不到元素
在您的情况下,您应该使用 bookmarklet 而不是 IE 菜单。在您的小书签中使用以下脚本获取元素值:
javascript: (function () { alert(document.getElementById("hello").value); })();
使用以下步骤添加小书签: