在IE上下文菜单扩展中获取页面URL [英] Get page URL in IE context menu extension

查看:241
本文介绍了在IE上下文菜单扩展中获取页面URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IE作为我的浏览器,我想要做的是:
1.在IE页面右键单击,然后单击一个自定义菜单,在我的本地调用外部脚本。
2.此外部脚本用于获取当前页面URL,我执行此右键单击操作。

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.

假设我打开 https://docs.microsoft.com/en我的IE浏览器中有-us / sql / t-sql / statements / drop-external-resource-pool-transact-sql ,然后我右键单击从我的本地执行我的外部脚本。
所以我想要的是确切的URL( https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-external-resource-pool-transact-sql

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)

我已经完成了第一步。但我找不到第二步的方法。
我想知道是否可以这样做?我想在我的本地外部脚本中使用 window.location.href; 。但是出来的位置是我本地PC中文件的位置,而不是浏览器的URL。
如果您知道怎么做,请提供帮助!

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!

推荐答案

确保您按照我分享的步骤进行操作< a href =https://stackoverflow.com/q/36473703/3110834> 向IE添加上下文菜单 。然后就可以使用以下脚本作为你的html文件的内容来获取页面的URL。

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.

你可以从窗口的文档对象中获取url:

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>

这篇关于在IE上下文菜单扩展中获取页面URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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