|
|
|
|
|
|
Re: Browser.setText + links [message #464169 is a reply to message #464167] |
Thu, 17 November 2005 21:13 |
Steven Wasleski Messages: 23 Registered: July 2009 |
Junior Member |
|
|
James Willans wrote:
> Hi Steve,
>
> Thanks for your suggestion, but unfortunately this is not the problem.
> I know that it is not working because when I click on the link, I get a
> new page displaying only "blank#link". I'm beginning to think that
> there is no easy solution to this.
>
> James
>
James,
I attached a LocationListener to the Browser object in your example and
watched what was going by. On initial load of your page, the location
is "about:blank" and upon clicking the link, it is "about:blank#link".
It appears there is a special "about:blank" page ("about" protocol to an
otherwise "blank" page) that is used to display contents set via the
setText method so that your base URL is set to "about:blank", therefore,
relative links like "#link" resolve to "about:blank#link". The resolved
URL is then treated like it came from setText("blank#link"), that is the
protocol is stripped and the rest is considered to be the page contents
and so you see what you see. I would recommend you open a bug report to
see if this could be handled better.
In the mean time, here is what I was able to get pretty much working as
you want it to. I had to add an onClick handler to do the scroll myself
and not let the browser handle it. Sorry about any formatting problems.
Also note that the '\n' between the two statements in the onClick
handler is very important.
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test {
public static void main(String[] args) {
/* Relative links: use the HTML base tag */
final String html = "<html><head>"
+ "<title>HTML Test</title></head>"
+ "<body><A ID=\"foo\" HREF=\"#link\">This is a link</A>"
+ "\n<script for=\"foo\" event=onclick
language=\"javascript\">document.all.link.scrollIntoView()\nreturn
false</script>"
+
"\n<br><br><br><br><br><br><br><br><br><br><br><br ><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br>"
+ "<A NAME=\"link\">This is the target</A></body></html>";
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
Browser browser = new Browser(shell, SWT.NONE);
browser.setText(html);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
|
|
|
Re: Browser.setText + links [message #464205 is a reply to message #464169] |
Fri, 18 November 2005 17:35 |
James Willans Messages: 303 Registered: July 2009 |
Senior Member |
|
|
Hi Steve,
> I attached a LocationListener to the Browser object in your example and
> watched what was going by. On initial load of your page, the location
> is "about:blank" and upon clicking the link, it is "about:blank#link".
> It appears there is a special "about:blank" page ("about" protocol to an
> otherwise "blank" page) that is used to display contents set via the
> setText method so that your base URL is set to "about:blank", therefore,
> relative links like "#link" resolve to "about:blank#link". The resolved
> URL is then treated like it came from setText("blank#link"), that is the
> protocol is stripped and the rest is considered to be the page contents
> and so you see what you see. I would recommend you open a bug report to
> see if this could be handled better.
> In the mean time, here is what I was able to get pretty much working as
> you want it to. I had to add an onClick handler to do the scroll myself
> and not let the browser handle it. Sorry about any formatting problems.
> Also note that the 'n' between the two statements in the onClick
> handler is very important.
Many thanks for your help, it is really appreciated. I have posted bug
117108 to deal with this issue, in the meantime I'll give your suggestion
a try.
Thanks again,
James
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.browser.Browser;
> import org.eclipse.swt.layout.FillLayout;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> public class Test {
> public static void main(String[] args) {
> /* Relative links: use the HTML base tag */
> final String html = "<html><head>"
> + "<title>HTML Test</title></head>"
> + "<body><A ID="foo" HREF="#link">This is a link</A>"
> + "n<script for="foo" event=onclick
> language="javascript">document.all.link.scrollIntoView()nreturn
> false</script>"
> +
>
"n<br><br><br><br><br><br><br><br><br><br><br><br ><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br><br>"
> + "<A NAME="link">This is the target</A></body></html>";
> Display display = new Display();
> Shell shell = new Shell(display);
> shell.setLayout(new FillLayout());
> Browser browser = new Browser(shell, SWT.NONE);
> browser.setText(html);
> shell.open();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> }
|
|
|
Powered by
FUDForum. Page generated in 0.07133 seconds