Get page URL in IE context menu extension

孤者浪人 提交于 2019-12-24 13:33:35

问题


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:


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>


来源:https://stackoverflow.com/questions/49041265/get-page-url-in-ie-context-menu-extension

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