ContextMenu in IE to get the current opened browser url

我们两清 提交于 2019-12-11 15:57:51

问题


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.

How to do this using Javascript? I tried using:

  alert(window.location.href);

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

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

回答1:


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

Bonus, for selected text in IE 11:

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

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



来源:https://stackoverflow.com/questions/48973126/contextmenu-in-ie-to-get-the-current-opened-browser-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!