aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Swings HTML URL problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swings HTML URL problem" Watch "Swings HTML URL problem" New topic
Author

Swings HTML URL problem

Bbk Reddy
Greenhorn

Joined: Dec 06, 2010
Posts: 2
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

Joined: Mar 12, 2010
Posts: 79
Use overloaded exec function, like this:

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

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: May 03, 2008
Posts: 4543
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Bbk Reddy
Greenhorn

Joined: Dec 06, 2010
Posts: 2
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

Joined: Oct 27, 2005
Posts: 19693
    
  20

The following works fine for me:
It's Desktop.browse that doesn't work for me.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
For a more cross-platform compatible approach, check out BareBonesBrowserLaunch.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swings HTML URL problem