在Javascript中的IE上下文菜单项(IE Context Menu Item In Javascript)

编程入门 行业动态 更新时间:2024-10-28 05:19:05
在Javascript中的IE上下文菜单项(IE Context Menu Item In Javascript)

我正在尝试创建一个IE上下文菜单项,指向一个Javascript html文件,如下所述https://msdn.microsoft.com/en-us/library/bb735853(v=vs.85).aspx#IEAddOnsMenus_topic1 “添加到上下文菜单”部分。 我在HKCU \ Software \ Microsoft \ Internet Explorer \ MenuExt中列出了上下文菜单条目,它指向一个带有javascript的html文件。 这是我正在使用的Javascript代码。

<script language="JavaScript"> function pausescript(ms) { ms += new Date().getTime(); while (new Date() < ms){} } { var win = window.open("http://www.example.com"); pausescript(2000); win.close(); } </script>

我试图弹出一个窗口到网址然后等待2秒并关闭窗口。 它正在工作,但当它关闭弹出窗口由于某种原因IE失去焦点,除IE之外的任何其他窗口重新获得焦点,即使我强制从IE上下文菜单弹出。 弹出窗口关闭后如何让IE获得焦点?

I am trying to create an IE Context Menu Item that points to a Javascript html file as described here https://msdn.microsoft.com/en-us/library/bb735853(v=vs.85).aspx#IEAddOnsMenus_topic1 under the "Adding to a context menu" section. I have the Context menu entry listed in HKCU\Software\Microsoft\Internet Explorer\MenuExt and it points to an html file with javascript in it. Here is the Javascript code I am using.

<script language="JavaScript"> function pausescript(ms) { ms += new Date().getTime(); while (new Date() < ms){} } { var win = window.open("http://www.example.com"); pausescript(2000); win.close(); } </script>

I am trying to pop up a window to the url then wait 2 seconds and close the window. It is working but when it closes the pop up window for some reason IE loses focus and any other window besides IE regains focus even though I am forcing the pop up from an IE context menu. How do I make IE get the focus after the pop up window closes?

最满意答案

您的问题是如何设置注册表。 我使用Windows 8.1并以这种方式设置注册表:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER \ Software \ Microsoft \ Internet Explorer \ MenuExt \&Live Search] @ =“C:\ Usr \ StackOverflow \ livesearch.htm”“Contexts”= dword:00000001

一切正常(你的脚本)。

就像你可以看到,上下文的值与指南中描述的不同(而不是我使用的是0x10)。

说你需要重新启动浏览器是没有用的。

焦点问题

关闭窗口poup窗口IE失去焦点。

像在MSDN中描述的那样,您需要访问external.menuArguments属性以获取当前的窗口处理程序ie。

所以javascript代码是:

<script language="JavaScript">

    function pausescript(ms) {
        ms += new Date().getTime();
        while (new Date() < ms){}
    }
    {
        var win = window.open("http://www.example.com");
        pausescript(2000);
        win.close();
        try {
            // access the current browser window
            var parentwin = external.menuArguments;

            // get the document element
            var doc = parentwin.document;

            // focus it
            doc.body.focus();
        } catch(ex) {
            alert(ex);
        }
    }
</script>

Your problem is how to set the registry. I use windows 8.1 and I set the registry in this way:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\&Live Search] @="C:\Usr\StackOverflow\livesearch.htm" "Contexts"=dword:00000001

All worked fine (your script).

Like you can see the value of Contexts is different from the one described in the guide (instead of 0x10 i used 1).

It's unusefull to say you need to restart the browser.

The FOCUS PROBLEM

After closing the window poup window IE loses the focus.

Like described in MSDN you need to access external.menuArguments property to get the window handler of current ie.

So the javascript code is:

<script language="JavaScript">

    function pausescript(ms) {
        ms += new Date().getTime();
        while (new Date() < ms){}
    }
    {
        var win = window.open("http://www.example.com");
        pausescript(2000);
        win.close();
        try {
            // access the current browser window
            var parentwin = external.menuArguments;

            // get the document element
            var doc = parentwin.document;

            // focus it
            doc.body.focus();
        } catch(ex) {
            alert(ex);
        }
    }
</script>

                    
                     
          

更多推荐

IE,window,上下文,Javascript,电脑培训,计算机培训,IT培训"/> <meta name="desc

本文发布于:2023-08-06 21:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上下文   菜单项   Javascript   Item   Menu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!