在IE中的ContextMenu获取当前打开的浏览器URL [英] ContextMenu in IE to get the current opened browser url

查看:189
本文介绍了在IE中的ContextMenu获取当前打开的浏览器URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE上下文菜单中创建了一个选项,所以当我打开IE,并在窗口中右键单击时,添加的菜单可用。现在我想做的是,我想得到当前窗口的url。因此,假设我打开www.facebook.com,然后我右键单击,然后选择其他菜单,我想获得www.facebook.com的位置。

I have created an option in IE context menu, so when I open IE, and right click in the window, the added menu is available. Now what I want to do is, I want to get the url of current window. So suppose I open www.facebook.com, then I right click, and choose the additional menu, I want to get the location as www.facebook.com.

如何使用Javascript执行此操作?我尝试使用:

How to do this using Javascript? I tried using:

  alert(window.location.href);

但是,该位置是我的test.html文件的位置:具有以下脚本:

However, the location is the location of my test.html file: which has this script:

<html>
alert(window.location.href);
</html>


推荐答案

在htm文件中,您要访问 external.menuArguments 属性,用于从您开始的页面访问上下文(即任何选择数据或原始dom文档对象)。这应该是你想要的href:

In the htm file, you want to access the external.menuArguments property to access the context from the page you started on (i.e. any selection data or the original dom document object). This should get you the href you're looking for:

external.menuArguments.document.href

奖励,对于IE 11中的选定文字:

Bonus, for selected text in IE 11:

external.menuArguments.document.getSelection().toString()

编辑:也,不要忘记将您的javascript包装在< script>< / script> 标签中!

also, don't forget to wrap your javascript in a <script></script> tag!

这篇关于在IE中的ContextMenu获取当前打开的浏览器URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆