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?
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>