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>
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:Bonus, for selected text in IE 11:
Edit: also, don't forget to wrap your javascript in a
<script></script>
tag!