Local links in html

18 views
Skip to first unread message

Gareth Murfin

unread,
Jan 2, 2019, 1:43:55 AM1/2/19
to CodenameOne Discussions
So I have decompressed a zip to storage and I am able to view the html pages that I have extracted. However when I click on a link inside these html pages then it doesnt work. The link is a relative one like this: "./../../key-concepts-kanji/empty-component.html", implying you need to go back a few dirs etc first, this works in a web browser on windows but not in cn1.

So my question is what do I do in cn1 to fix this? I presume I need to manipulate that link in the html itself before I set the data to the browser? Any examples around?

Gareth Murfin

unread,
Jan 2, 2019, 1:47:38 AM1/2/19
to CodenameOne Discussions
Ive noticed that actually clicking the link doesnt even go to not found page, do I need to turn them on somehow ?

Shai Almog

unread,
Jan 2, 2019, 10:43:21 PM1/2/19
to CodenameOne Discussions
This should work if you used file system storage. Is this on the simulator or device?

Gareth Murfin

unread,
Jan 3, 2019, 7:28:24 AM1/3/19
to CodenameOne Discussions
Hi Shai, thanks for the reply, this is on the simulator. And yes I used filesystem storage, I can load html fine from java code but tapping links in BrowserComponent seemingly does nothing, could you try it on a simulator? I can send my project if it helps.

Shai Almog

unread,
Jan 3, 2019, 10:31:17 PM1/3/19
to CodenameOne Discussions
I just tried a simple test case and it worked for me. It's possible that this is due to a fix we made to file: URL handling. How do you load the initial file URL?

Gareth Murfin

unread,
Jan 4, 2019, 4:06:02 AM1/4/19
to CodenameOne Discussions
Actually thats a good point, I couldnt get it to load properly, so I had to pass html as a string, that could be the issue?

InputStream in;                            
        try 
        {
            in = FileSystemStorage.getInstance().openInputStream(FileSystemStorage.getInstance().getAppHomePath()+path);
            String html = Util.readToString(in);                        
            _("html loaded is ->");
            _("\n"+html);
            //fire up the html in middle 
            browser.setPage(html, FileSystemStorage.getInstance().getAppHomePath());                         
            form.add(BorderLayout.CENTER, browser);     
           
            Button back = new Button("Back");                 
            back.addActionListener(new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent evt) {
                   _("back hit z");
                   createMainForm();//show main form again
                }
            });
            form.add(BorderLayout.SOUTH, back);                 
            form.show();
        } catch (IOException ex) {
            //Logger.getLogger(Outlier.class.getName()).log(Level.SEVERE, null, ex);
            _("WARNING! error loading html "+ex.getMessage());
            ToastBar.showErrorMessage("can't find "+path);

Gareth Murfin

unread,
Jan 4, 2019, 5:18:31 AM1/4/19
to CodenameOne Discussions
I suppose passing the html loses any info about where the current directory is, i will try loading properly now that it is fixed

Shai Almog

unread,
Jan 5, 2019, 12:11:26 AM1/5/19
to CodenameOne Discussions
Yes, there is no base URL. This should work with the update from yesterday, make sure to update project libs.

Gareth Murfin

unread,
Jan 6, 2019, 11:28:51 PM1/6/19
to CodenameOne Discussions
Yes that now works very well thanks Shai!.. 

Gareth Murfin

unread,
Jan 8, 2019, 8:41:49 AM1/8/19
to CodenameOne Discussions
Links work fine now but I have noticed that even with setUrl images referenced in the page will not display, this same html page works fine in a normal browser on pc and images are displayed.

Gareth Murfin

unread,
Jan 8, 2019, 9:06:41 AM1/8/19
to CodenameOne Discussions
looks like im wrong as usual :) they DO load but not if there are chinese characters in their names, which is weird because if I go directly to view a .svg with chinese characters in its name it does work, but from html it does not, why would this be?

Im wondering if I can somehow convert the chinese into roman alphabet characters when I do the intial extract to storage.

Shai Almog

unread,
Jan 8, 2019, 10:41:56 PM1/8/19
to CodenameOne Discussions
Non-ascii characters might fail here, this might work on the device and might fail on the device. I don't know. This isn't something we tested.
Reply all
Reply to author
Forward
0 new messages