Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swings HTML URL problem

 
Bbk Reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one swings application which when ran has a menu item which opens the HTML path from local system(Like - file:///C:/index.html )....If the file is there then it is working properly using below code

String browserPath = "C:\Program Files\Internet Explorer\iexplore.exe";
String url = "file:///C:/index.html";
Runtime.getRuntime().exec(browserPath+" "+url);

But if the path is changed to (Like - file:///C:/index.html#section1) then the real problem is occuring....In IE it is loading the same index.html but it is not loading the sub section #section1 directly. I dont know why the #section1 is not loading directly

Can any one please help in this problem
 
Andrey Kozhanov
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use overloaded exec function, like this:

Runtime.getRuntime().exec(new String [] {browserPath, url});
 
Paul Clapham
Sheriff
Posts: 21140
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bbk Reddy wrote:In IE it is loading the same index.html but it is not loading the sub section #section1 directly


And if you just type that URL into IE's address bar, or copy and paste it there, does IE work differently? If your answer is no, it's the same, then that would suggest it isn't a Swing (not "swings") problem. It's always a good idea to try to identify which part of the code is causing the problem, rather than just giving up when there are multiple parts.
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a further difference between pasting a link to an internal anchor of an HTML page/file in the browser address bar and launching the browser with the link as an argument. In the first case, IE correctly scrolls the page to the internal anchor; but in the second, it doesn't.

So, when launching the browser via Runtime#exec(...) the page will be opened, but the internal anchor will be ignored. I would consider this a bug wither in IE or the Windows shell.
 
Bbk Reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrey Kozhanov wrote:Use overloaded exec function, like this:

Runtime.getRuntime().exec(new String [] {browserPath, url});


I tried the same but still not working....

I think the problem is arising because of '#' and because of string tokenizer.....Is it so?? any other solution is there???

 
Rob Spoor
Sheriff
Pie
Posts: 20550
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following works fine for me:
It's Desktop.browse that doesn't work for me.
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a more cross-platform compatible approach, check out BareBonesBrowserLaunch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic