Get page URL in IE context menu extension

2019-07-24 23:31发布

I am using IE as my browser, what I want to do is : 1. to do right click in IE page, then click a custom menu which call an external script in my local. 2. this external script is used to get the current page url where I do this right click action.

Supposed I open https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-resource-pool-transact-sql in my IE browser, then I do right click to execute my external script from my local. So what I want to get is the exact URL (https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-resource-pool-transact-sql)

I have done the 1st step. But I can't find a way to do the 2nd step. I wonder if it is possible to do? I imagine to use window.location.href; in my external script in my local. But the location that comes out is location of the file in my local PC, not the URL from browser. Please help if you know how to do this!

1条回答
乱世女痞
2楼-- · 2019-07-24 23:43

Make sure you followed the steps which I shared about adding context menu to IE. Then it's enough to use the following script as content of your html file to get url of the page.

You can get the url from document object of the window:

<script type="text/javascript">
    var parentwin = external.menuArguments;
    var url = parentwin.document.URL;
    alert(url)
</script>
查看更多
登录 后发表回答