c
xml
ajax
mysql
linux
android
regex
eclipse
silverlight
flash
html5
json
perl
facebook
tsql
apache
mvc
asp
postgresql
dom
Another way to do it (from How to launch a file protocol URL with an anchor from Java? ):
Runtime.getRuntime().exec("cmd.exe start file:///C:/foo/bar.html#anchor")
Yet another link with this issue (using url.dll) shows the author reverting to trying an external program, in this case Quero: Runtime.getRuntime().exec("cmd.exe qlaunch.exe open=\"file:///c:/temp/test.html?p=1\"");
Runtime.getRuntime().exec("cmd.exe qlaunch.exe open=\"file:///c:/temp/test.html?p=1\"");
From what I can tell, this is a bug in Windows and/or Internet Explorer in particular. Firefox has other issues with the file:// protocol that you have to manually disable.
file://
This is definitely either expected behavior or a bug in Windows itself. Using Desktop.browse (which sends the URI clean to ShellExecute) or cmd.exe start or Runtime.getRuntime().exec("rundll32 url.dll " + uri) or even just opening a command prompt and typing the file:// URI itself just ends up doing this (which I found via Process Monitor):
Desktop.browse
cmd.exe start
Runtime.getRuntime().exec("rundll32 url.dll " + uri)
Order of operations shown:
#
?
Note that calling start iexplore file:///c:/temp/test.html#mark does work because it's just passing the parameter without trying to do anything special.
start iexplore file:///c:/temp/test.html#mark
Note that steps 2 and 3 violate Microsoft's own advice from 2006 (see here) but from what I've seen this behavior was introduced at the time that IE7 was released. My guess is that this fixed some bug or security flaw in Windows at the cost of being able to do this at all.
With some more research, it appears that file: URIs in Windows have had a very sordid past
file:
Oddly enough, a Microsoft article from 2010 shows file://host/path/file.txt?Query#fragment as a valid URI in .Net...
file://host/path/file.txt?Query#fragment
I think you might be out of luck until someone finds a magical Registry setting - or you can manually call a browser (e.g. Runtime.getRuntime().exec(chromepath + "chrome.exe file:///c:/temp/test.html#jump") or Runtime.getRuntime().exec(iepath + "iexplore.exe file:///c:/temp/test.html#jump"))
Runtime.getRuntime().exec(chromepath + "chrome.exe file:///c:/temp/test.html#jump")
Runtime.getRuntime().exec(iepath + "iexplore.exe file:///c:/temp/test.html#jump")
Or, for fun: Runtime.getRuntime().exec("cmd.exe start iexplore " + myURL)
Runtime.getRuntime().exec("cmd.exe start iexplore " + myURL)
Use Desktop.browse(URI) (which has a chance of working on *nix and OS X as well as Windows).
Desktop.browse(URI)
OK - scratch that. The net based URIs will scroll to the anchor, disk based URIs will not. Raised a bug report with Oracle (ID: 7143677 - Desktop.browse() - Anchors are ignored for local URIs).
Desktop.browse()