我正在尝试创建一个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
发布评论