Simple web browser with bookmarks (iPad/iPhone/iPod touch)

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Simple web browser with bookmarks (iPad/iPhone/iPod touch)

Post by Dav »

Playing around with the browser command turned into a simple web browser. Uses JavaScript for some browser functions. Does forward,back,reload,stop,home page, enter url, quit. Has a basic bookmark manager allowing you to save/load your favorite bookmarks. Browser resizes with screen orientation. Set your homepage with the home$ variable (default is google).

Latest version works with iPad, iPhone and iPod touch. Can use previous versions bookmarks.ini file (wouldn't erase your saved bookmarks running this new version).

- Dav

EDIT: v1.08 - Added infobar at top showing connection status, time & battery level. Bookmark menu now drops down & rises out of sight (animated). Added current url display. You can select it's field and copy current url to clipboard. Redesigned layout a little.

Code: Select all

'=========================================
'Simple web browser in smart BASIC - v1.08
'=========================================
'Works on ipad, iphone, ipod touch
'Coded by Dav, December/2015
'
'A simple web browser made in smart Basic.
'Uses javascript for browsing functions.
'Has a basic bookmark manager. Only loads
'one page at a time, but I'm working on a
'multitab version right now...
'
'NEW:  Shows info bar at top: Connection
'      status, Time, Battery level.  The
'      current url now shown below menu.
'      You can select it to copy url.
'      Bookmark menu now drops down and
'      closes up out of sight (moving).
'
'NOTE: Bookmarks saved in file in current
'      directory named: 'bookmarks.ini'
'      Homepage is set to GOOGLE.COM, but
'      you can change this by changing
'      the home$ variable below...

home$="http://www.google.com" '<<< change

'detect users device
if lowstr$(device_type$())="ipad" then
  dev=1
else
  dev=0
end if

graphics
option base 1
set buttons custom

page "main" set

'init screen
graphics clear .4,.4,.4
set toolbar off

set browsers scaled 'allow zooming in/out

'get current screen width
curwidth= screen_width()

gosub drawinfobar

'load the homepage
url$=home$
gosub loadpage

draw color 0,0,0
fill color .9,.9,.9

'make buttons
if dev = 1 then
  set buttons font size 36
  button "back" text " "&chr$(9666)&" " at 10, 28
  button "forward" text " "&chr$(9656)&" " at 70, 28
  button "stop" text " "&chr$(9679)&" " at 130,28
  button "reload" text " "&chr$(8634)&" " at 194,28
  button "home" text " "&chr$(9751)&" " at 266,28
  button "bookmarks" text "Bookmarks..." at 344,28
  button "url" text "Url..." at 579,28
  button "quit" text "Quit" at 676,28
else
  set buttons font size 20
  button "back" text chr$(9666) at 3, 28
  button "forward" text chr$(9656) at 40, 28
  button "stop" text chr$(9679) at 78,28
  button "reload" text chr$(8634) at 113,28
  button "home" text chr$(9751) at 153,28
  button "bookmarks" text chr$(9873) at 195,28
  button "url" text chr$(9166) at 235,28
  button "quit" text "X" at 285,28
end if

'main loop...
do

  if button_pressed("back") then
    u$ = browser_text$("n", "window.history.go(-1)")
  end if

  if button_pressed("forward") then
    u$ = browser_text$("n", "window.history.go(1)")
  end if

  if button_pressed("quit") then break

  if button_pressed("home") then 
   url$=home$ ! gosub loadpage
  end if

  if button_pressed("url") then
   gosub geturl
  end if

  if button_pressed("stop") then
    u$ = browser_text$("n", "stop()")
  end if

  if button_pressed("reload") then
    u$ = browser_text$("n", "location.reload(true)")
  end if

  if button_pressed("bookmarks") then
    gosub bookmarks
  end if

  'if screen rotated...
  if screen_width() <> curwidth then
    curwidth = screen_width()
    url$=browser_text$("n", "window.location.href")
    gosub loadpage
    gosub drawinfobar
  end if

  'update infobar and connection every 10 secs
  if time()>10 then
    refresh off
    gosub drawinfobar
    refresh on
    time reset
  end if

  'check current url location every other second
  'if it changes, update field to show the change
  if odd(time()) then
    title$=browser_text$("n", "window.location.href")
    ft$=field_text$("url")
    'if it's changed, show change in field
    if title$ <> ft$ then
      field "url" back color 1,1,1
      field "url" font color 0,0,0 
      if dev=1 then
        field "url" text title$ at 10,85 size screen_width()-20,24
      else
        field "url" text title$ at 5,65 size screen_width()-5,25
      end if
    end if
  end if

until 0

set toolbar on

page bm$ hide
page "main" hide
text

end


'==========================================
'              G O S U B S
'==========================================

'-------
loadpage:
'-------

field "url" back color 1,1,1
field "url" font color 0,0,0 
if dev=1 then
  browser "n" url url$ at 0,110 size screen_width(),screen_height() -110 
  title$=browser_text$("n", "window.location.href")
  field "url" text title$ at 10,85 size screen_width()-20,24
else
  browser "n" url url$ at 0,95 size screen_width(),screen_height() -95
  title$=browser_text$("n", "window.location.href")
  field "url" text title$ at 5,65 size screen_width()-5,25 
end if
return


'----------
hidebuttons:
'----------

button "back" hide
button "forward" hide
button "stop" hide
button "reload" hide
button "home" hide
button "bookmarks" hide
button "url" hide
button "quit" hide
return


'----------
showbuttons:
'----------

button "back" show
button "forward" show
button "stop" show
button "reload" show
button "home" show
button "bookmarks" show
button "url" show
button "quit" show
return


'-----
geturl:
'-----

gosub hidebuttons

if dev=1 then
  field "geturl" text "" at 0,0 size screen_width(), 60
else
  field "geturl" text "" at 0,0 size screen_width(), 38
end if

field "geturl" set text "http://"
field "geturl" select

if dev=1 then
  button "cancel" text "Cancel" at screen_width()-150,3
else
  button "cancel" text "Cancel" at screen_width()-80,3
end if

do
  if button_pressed("cancel") then goto skip
until field_changed("geturl") = 1

u2$ = field_text$("geturl")

if u2$ <> "" and u2$ <>"http://" then
   u2$=ltrim$(u2$)
   'make sure http:// given
   if capstr$(left$(u2$,7))<> "HTTP://" then
     u2$="http://"&u2$
   end if
   url$=u2$
   gosub loadpage
end if

skip:
button "cancel" delete
field "geturl" delete
gosub showbuttons
return


'--------
bookmarks:
'--------

gosub loadbookmarks

sw=screen_width()
sh=screen_height()

'make bookmarks page
bm$ = "Bookmarks"
page bm$ set
page bm$ frame 0,0,sw-10,sh/2
page bm$ color .7,.7,.7,1
if dev=1 then
  page bm$ at 5,-1000 '60
else
  page bm$ at 5,-1000 '50
end if

button "bookmarks" hide

showbookmarks:

if dev=1 then
  list bm$ text list$(1) at 4,4 size sw-18,sh/2-62
else
  list bm$ text list$(1) at 4,4 size sw-18,sh/2-42
end if

list bm$ set text list$

if dev=1 then
  button "close" text "Close" at sw- 130,sh/2-57
  button "addpage" text "Add Current" at 5,sh/2-57
  button "deletepage" text "Delete page" at 225,sh/2-57
  button "deletepage" hide
  button "loadpage" text "Load page" at 442,sh/2-57
  button "loadpage" hide
else
  button "close" text "Close" at sw- 85,sh/2-36
  button "addpage" text "Add" at 5,sh/2-36
  button "deletepage" text "Delete" at 65,sh/2-36
  button "deletepage" hide
  button "loadpage" text "Load" at 145,sh/2-36
  button "loadpage" hide
end if

'only drop down menu first time
if bdown=0 then
  for yy = -500 to 100 step 4
    page bm$ at 5,yy
    pause .001
  next yy
  bdown=1 'mark as down
end if

do

  if list_selected(bm$) <> -1 and booknum > 0 then 
    button "deletepage" show
    button "loadpage" show
     
    if button_pressed("loadpage") then
      pause .2 'delay to look like a click
      url$=list$(list_selected(bm$))
      'page "main" set
      gosub showbuttons
      for yy = 100 to -550 step -4
        page bm$ at 5,yy
        pause .001
      next yy
      gosub loadpage
      goto bookdone
    end if

    if button_pressed("deletepage") then
      list$(list_selected(bm$))=""
      gosub deletebookmark
      gosub savebookmarks
      goto showbookmarks
    end if

  end if

  if button_pressed("addpage") then
     url$=browser_text$("n", "window.location.href")
     if url$<>"" then
        gosub addbookmark
        gosub savebookmarks
        goto showbookmarks
     end if 
  end if

  if screen_width() <> curwidth then
     curwidth = screen_width()
     url$=browser_text$("n", "window.location.href")
     gosub drawinfobar
     gosub loadpage
     goto bookmarks
  end if

until button_pressed("close")

'raise menu back up
for yy = 100 to -550 step -4
   page bm$ at 5,yy
   pause .001
next yy

bookdone:

page "main" set
gosub showbuttons
bdown=0
return


'------------
loadbookmarks:
'------------

if file_exists("bookmarks.ini") =0 then
   makenew:
   'make default list of bookmarks
   booknum=5
   DIM list$(booknum)
   list$(1)="http://www.google.com"
   list$(2)="http://www.qbasicnews.com/dav/"
   list$(3)="http://www.yahoo.com"
   list$(4)="http://kibernetik.pro"
   list$(5)="http://www.bing.com"
   gosub savebookmarks
else
   file "bookmarks.ini" setpos 0
   file "bookmarks.ini" readline a$
   if a$ = "" then goto makenew
   booknum = val(a$)
   if booknum < 0 then goto makenew
   if booknum = 0 then
     dim list$(1)
   else
     dim list$(booknum)
     for p = 1 to booknum
       file "bookmarks.ini" readline a$
       'if invalid entry for some reason
       if a$ ="" then
         'last booknum was last
         bookmark = p -1
         break
       end if
       list$(p) = a$
     next p
   end if
end if
return


'------------
savebookmarks:
'------------

'out with the old...
file "bookmarks.ini" delete

'in with the new...
if booknum = 0 then
   file "bookmarks.ini" writeline str$(0)
else
   file "bookmarks.ini" writeline str$(booknum)
   for p = 1 to booknum
     file "bookmarks.ini" writeline list$(p)
   next p
end if
return


'-------------
deletebookmark:
'-------------

if booknum > 1 then
  'temporary holder array
  dim temp$(booknum)
  bc=1
  for h=1 to booknum
    if list$(h) <>"" then
      temp$(bc)=list$(h)
      bc=bc+1
    end if
  next h
  'remake list$()
  booknum =bc -1
  dim list$(booknum)
  'copy temp$() to list$()
  for p = 1 to booknum
    list$(p)= temp$(p)
  next p
else
  booknum=0
end if
return


'----------
addbookmark:
'----------

booknum=booknum + 1

if booknum = 1 then
  dim list$(1)
  list$(1) = url$
else
  'make temp array holder
  dim temp$(booknum)
  for p = 1 to booknum -1
      temp$(p) = list$(p)
  next p
  temp$(booknum) = url$
  'make new list$()
  dim list$(booknum)
  for p = 1 to booknum
     list$(p) = temp$(p)
  next p
end if
return


'----------
drawinfobar:
'----------

sw=screen_width()
fill color .7,.7,.7
fill rect 0,0 to sw,25
draw color .3,.3,.3
ampm$="AM" ! hr=current_hour()
min$=str$(current_minute())
if len(min$)=1 then min$="0"&min$
if hr>11 then ampm$="PM"
if hr>12 then hr=hr-12
if hr=0 then hr=12
tm$=str$(hr)&":"&min$&" "&ampm$
draw text tm$ at ((sw/2)-text_width(tm$)/2),4
if dev=1 then
  bat$=str$(battery_level())&"%"
  draw text bat$ at sw-text_width(bat$)-80,4
end if
draw rect sw-70,5 to sw-20,19
f=battery_level()/2
fill color .3,.3,.3
fill rect sw-70,5 to sw-70+f,19
fill rect sw-20, 9 to sw-17, 14
if system_ext_ip$() ="" then
     fill color .7,.7,.7
     fill rect 0,0 to 110,25
     fill color .7,0,0
     draw color .3,.3,.3
     if dev=1 then
        draw text "OFFLINE" at 25,3
     else
        draw text "OFF" at 25,3
     end if
else 
     fill color .7,.7,.7
     fill rect 0,0 to 110,25
     fill color 0,.7,0
     draw color .3,.3,.3
     if dev=1 then
        draw text "ONLINE" at 25,3
     else
        draw text "ON" at 25,3
     end if
end if
fill circle 12,12 size 5,5
draw color 0,0,0
fill color .9,.9,.9
return
ipad & ipod screenshots follow...
Attachments
browser108-ipad.jpg
browser108-ipad.jpg (95.74 KiB) Viewed 6892 times
browser108-ipod.jpg
browser108-ipod.jpg (97 KiB) Viewed 6892 times
Last edited by Dav on Thu May 17, 2018 2:24 pm, edited 14 times in total.

User avatar
Фант
Posts: 1363
Joined: Sat Nov 30, 2013 10:01 am
My devices: iPad 4 (iOS 9.3), iMac (MAC OS 11.03)
Location: Россия,Санкт-Петербург
Flag: Russia
Contact:

Re: simple web browser with common functions

Post by Фант »

Hello Dav! i need help! tell me how to share in the smart Basic files between devices using html? You can set an example code?

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: simple web browser with common functions

Post by Dav »

Hello Фант. You have made some excellent smart basic programs! I hope I can help you.

Here are the only ways I know how to share files in smart Basic without using DropBox.

Using only smart Basic (FROM a smart Basic device TO a smart Basic) I don't know if a transfer is possible. I have only been able to get files into smart Basic by using HTTP command to download files. I do not know if HTTP command can send files. That would be very cool if it could!


TO GET FILES INTO SMART BASIC FROM LAPTOP/INTERNET WITHOUT DROPBOX:

To download files from off my website, I use this way:

Code: Select all

http "www.qbasicnews.com/dav/Winstone.txt" getdim m 
file "Winstone.txt" writedim m
To get files from off my Windows PC laptop at home instead, I have to run an HTTP server on the laptop first. I am using the smallweb server, but you can use any HTTP server. When running that I can HTTP download using smart Basic, only point HTTP to my laptop device IP instead. The HTTP server gives me the correct IP address to use.

Code: Select all

http "192.168.0.109/Memorygame.txt" getdim m  '<< just an example IP address....
file "Memorygame.txt" writedim m
That is how I could play DutchMans sea combat game, I had to HTTP download each file using HTTP command.


TO GET FILES OUT OF SMART BASIC TO MY LAPTOP WITHOT DROPBOX:

The only way I have been able to get files out of smart Basic is by loading text files into the editor, copying the text, and paste it into another App that has wifi transfer ability. Like iFiles or WiFiles. After that I can transfer that file to my laptop using those Apps.

To get a non-text file out of smart Basic (like an JPG image, or a .MID file) I have to first convert the file to a text file (using a program I made), Then I can load it into the editor and copy/paste it to iFiles, then transfer it by wifi. After doing that, on my laptop, I have to convert that text file back into the original binary file using another program made on my laptop. It is alot of steps, but it worked for me, and is how I was able to get my Winstone.COD out of smart Basic without using DropBox. I can post the text encoding program if you would like.

EDIT: The text encoder just saves each byte to a ASCII code in a text file, so bytes CHR(34) + CHR(35) in a file would be saved as 034035 in the text file for example.

DropBox is easier, but I enjoyed the challenge of trying to transfer without it.

- Dav
Last edited by Dav on Fri Feb 06, 2015 2:11 pm, edited 3 times in total.

User avatar
Фант
Posts: 1363
Joined: Sat Nov 30, 2013 10:01 am
My devices: iPad 4 (iOS 9.3), iMac (MAC OS 11.03)
Location: Россия,Санкт-Петербург
Flag: Russia
Contact:

Re: simple web browser with common functions

Post by Фант »

Thank you for taking the time to answer! this process is complicated for me. I will try to understand it! I hope for your help!

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: simple web browser with common functions

Post by Dav »

You are very welcome.

I have updated this simple browser code above. Added bookmark page and URL entering and browser resize when screen orientation changes.

For now you have to change bookmarks in the code to yours, but I am planning to use FILES to save bookmarks and then add an Add bookmark feature.

Thanks to DutchMan for your pages demo, I learned how to put a list on a new page by your demo.

- Dav

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: simple web browser with common functions

Post by Dutchman »

Thanks Dav. I will certainly use your browsercode. A handy way to acces my iMac :D
Your code works fine!
First I have to setup a server on my Mac ;)

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: simple web browser with common functions

Post by Dutchman »

Well coded Dav!
Nice browser without commercial windows :D
It is amazing that a browser can be made with such a short program.
You probably have a lot of experience with browser commands.
I could not have made this program.
Thanks :D

- I made a little modification so that bookmarks can be added in lines of DATA.
- It would be helpfull if URL's could be entered in the DATA with or without the leader "http://"
- It would also be nice if the DATA-lines with label are entered as an include file. Then the list is unchanged if the program is updated.
- if the list of bookmarks is extended then an annoying black bar is added in the 'page'
I have not corrected that.

Code: Select all

' Dav's browser
'==========================
'Simple web browser - v1.02
'==========================
'Uses javascript for browsing functions
'coded by Dav for smart Basic, FEB/2015
'
'NEW: Added bookmarks and Enter a URL.
'     Browser resizes with orientation.
'     Fixed Browser size.


option base 1
'========== init screen
graphics clear 1,1,1
set toolbar off
'allow zooming in/out
set browsers scaled
'get current screen width
curwidth= screen_width()
'load the homepage
home$="http://www.google.com" 'homepage...
url$=home$
'load homepage
gosub loadpage


'========== make list of bookmarks
BookmarksData:
DATA "http://www.google.com","http://www.qbasicnews.com/dav/"
DATA "http://www.yahoo.com","http://kibernetik.pro"
DATA "http://www.bing.com","http://bit.ly/16tDaI4"
DATA "#" 'end of list
GOSUB MakeBookmarksList

'========== make buttons
button "back" text "<" AT 10, 3
button "forward" text ">" AT 60, 3
button "stop" text "Stop" at 110,3
button "reload" text "Reload" at 180,3
button "home" text "Home" at 260,3
button "bookmarks" text "Bookmarks..."at 340,3
button "url" text "Enter URL..." at 480,3
button "quit" text "Quit" at 680,3

'========== main loop...
do
 if button_pressed("back") then
    u$ = browser_text$("n", "window.history.go(-1)")
 end if
 if button_pressed("forward") then
    u$ = browser_text$("n", "window.history.go(1)")
 end if
 if button_pressed("quit") then break
 if button_pressed("home") then 
   url$=home$
   gosub loadpage
 end if
 if button_pressed("url") then
   gosub geturl
 end if
 if button_pressed("stop") then
       u$ = browser_text$("n", "stop()")
 end if
 if button_pressed("reload") then
       u$ = browser_text$("n", "location.reload(true)")
 end if
 if button_pressed("bookmarks") then
       gosub bookmarks
 end if
 if screen_width() <> curwidth then
     curwidth = screen_width()
     gosub loadpage
 end if
until 0
set toolbar on
end


'========= S U B R O U T I N E S ============
MakeBookmarksList:
'make a list of bookmarks
RESTORE TO BookMarksData
marks=0
READ mark$
WHILE mark$<>"#"
  READ mark$ ! marks+=1
END WHILE
dim list$(marks)
RESTORE TO BookMarksData
FOR i=1 TO marks
  READ list$(i)
NEXT i
RETURN
'==============
loadpage:
browser "n" url url$ at 0,40 size screen_width(),screen_height() -40
return
'===============
hidebuttons:
button "back" hide
button "forward" hide
button "stop" hide
button "reload" hide
button "home" hide
button "bookmarks" hide
button "url" hide
button "quit" hide
return
'===============
showbuttons:
button "back" show
button "forward" show
button "stop" show
button "reload" show
button "home" show
button "bookmarks" show
button "url" show
button "quit" show
return
'===============
geturl:
gosub hidebuttons
field "geturl" text "" at 0,0 size screen_width(), 38
field "geturl" set text "http://"
field "geturl" select
button "cancel" text "cancel" at 600,3
do
  if button_pressed("cancel") then goto skip
until field_changed("geturl") = 1
u2$ = field_text$("geturl")
if u2$ <> "" and u2$ <>"http://" then
   u2$=ltrim$(u2$)
   ' make sure http:// given
   if capstr$(left$(u2$,7))<> "HTTP://" then
      u2$="http://"&u2$
   end if
   url$=u2$
   gosub loadpage
end if
skip:
button "cancel" delete
field "geturl" delete
gosub showbuttons
return
'===============
bookmarks:
'make bookmarks page
bm$ = "Bookmarks"
page bm$ set
page bm$ frame 0,0,600,300
page bm$ color .3,.3,.3,1
page bm$ at 50,5
'list bookmarks...
list bm$ text list$(1) at 2,2 size 595,260
list bm$ set text list$
button "close" text "close" at 530,265
do
  if list_selected(bm$) <> -1 then 
    pause .2 'delay to look like a click
    url$=list$(list_selected(bm$))
    page "" set
    gosub loadpage
    break
  end if
until button_pressed("close")
page "" set   'go back to default page...
return

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Simple web browser with common functions (iPad)

Post by Dav »

Thanks Dutchman. I appreciate your input and any modifications you may like to add.

I have made another browser version today and added a Bookmarks manager. Now you can add/delete favorite bookmarks. The bookmarks list is saved in a file called bookmarks.ini in the current directory.

The code in first post is updated.

- Dav

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: Simple web browser with common functions (iPad)

Post by Dutchman »

That is an excellent extension Dav. It works great!

I added 'GOSUB hidebuttons' just before 'END' in the main loop.
Now the message "Finished" is visible at program end.
The last browser-page remains visible but the buttons are gone and that is a clear indication that the browser is not operational and that page not 'active'.

I think you should add deletion of the buttons.
Buttons are created by the system and I learned that they will stay there until deletion.
Maybe you should fill an array with the button properties so that you can simply generate, hide or delete them in a FOR … NEXT loop. It will also reduce code-size.

Anyhow you made a great program. In my opinion it should be added to the Examples in the "Interactive Interface" folder.

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Simple web browser with common functions (iPad)

Post by Mr. Kibernetik »

Dutchman wrote: In my opinion it should be added to the Examples in the "Interactive Interface" folder.
Program by Dav is very useful. And his coding style is incredibly clear.
But any program sample should be able to run both on iPad and iPhone.

Post Reply