>Dear All,
>
>Probably aiming at the impossible, but does anyone know how to open an URL in the default browser, through ShellExecute or other shell method, in a way that will launch the browser in a named window? That is, the functional equivalent of the target attribute of the HTML anchor element? It may be browser-specific (most probably, it has to be), but must be runnable from the command line.
>
>Thanks in advance (that will cover a no-can-do seal, also, of course!).
I think that I understand now
why what I was looking for is not only impossible, but also undesirable.
A named window is not shared between different unrelated pages. If a page could access the name of windows that a browser is holding for its different script environments, or the windows, themselves, then they could be referenced or even hijacked by a malicious script.
While trying to put this together, I wrote a small proxy program to load a page in a specific named window. It goes like this (it's not my first version, that was more obvious, but it's functionally equivalent):
<html>
<head/>
<body>
<script type="text/javascript">
var target = window.open("", "targetWindow");
if (target){
target.location.href = window.location.search.substr(1);
window.close();
} else alert("Could not retrieve the targeted URL");
</script>
</body>
</html>
It can be ran from
http://www.aftlopes.com/proxy.html, by giving an URL as its query string.
Now, if you run the proxy in a browser, for instance,
http://www.aftlopes.com/proxy.html?http://vfpx.codeplex.com, it will open the target URL (provided you gave it the permission to open windows) in a new window/tab named targetWindow. If you refresh the proxy, the target URL is reloaded as well, in the same window that was used in the first run.
But, if you open a new tab and launch the proxy again, the same
http://www.aftlopes.com/proxy.html?http://vfpx.codeplex.com, it will run in a new script environment, with a new and different "targetWindow" of its own.
And that what's happens with ShellExecute: the browser is launched and instantiates a new script environment, that can not reference the objects of other running environments.
I wish I could be wrong about all this, of course, and would look forward to be corrected...
----------------------------------
António Tavares Lopes