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

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 »

I have modified the handling of buttons and added a sub 'DeleteButtons'

Code: Select all

'Dav's Browser
'==========================
'Simple web browser - v1.04
'==========================
'A simple web browser for smart Basic.
'Uses javascript for browsing functions.
'Has a basic bookmark manager.
'Coded by Dav , FEB/2015
'
'NEW: Added bookmark manager page.
'     You can now add/delete bookmarks.
'     Bookmarks saved in file in current
'     directory named: 'bookmarks.ini'

'NOTE: Homepage is set to google.com.
'      You can change this by changing
'      the home$ variable.

option base 1

page "main" set

'init screen
graphics clear 1,1,1
set toolbar off

set browsers scaled 'allow zooming in/out

'get current screen width
curwidth= screen_width()

'load the homepage
home$="http://www.google.com" 'homepage...
url$=home$

gosub loadpage   'load homepag

'make buttons
Buttons=8
DIM Button$(buttons,4)
ButtonsData:'ID,txt,x,y
DATA "back","<",10, 3
DATA "forward",">",60, 3
DATA "stop","Stop",110,3
DATA "reload","Reload",180,3
DATA "home","Home",260,3
DATA "bookmarks","Bookmarks...",340,3
DATA "url","Enter URL...",480,3
DATA "quit","Quit",680,3
GOSUB LoadButtons
CALL MakeButtons

'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
gosub DeleteButtons
end


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

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

browser "n" url url$ at 0,40 size screen_width(),screen_height() -40
return

'-------
LoadButtons:
RESTORE TO ButtonsData
FOR i=1 to Buttons
  FOR j=1 to 4
    READ Button$(i,j)
  NEXT j
NEXT i
RETURN

'-------
DEF MakeButtons
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) text .Button$(i,2) AT .Button$(i,3),.Button$(i,4)
  NEXT i
END DEF

'-------
DeleteButtons:
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) DELETE
  NEXT i
RETURN

'----------
hidebuttons:
'----------
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) HIDE
  NEXT i
return

'----------
showbuttons:
'----------
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) SHOW
  NEXT i
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:
'--------

gosub loadbookmarks

'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,50

showbookmarks:

LIST bm$ TEXT list$(1) AT 2,2 SIZE 595,260
LIST bm$ SET TEXT list$

BUTTON "close" text "close" AT 525,265

button "addpage" text "Add Current" at 20,265
button "deletepage" text "Delete Selected" at 160,265
button "deletepage" hide
button "loadpage" text "Load Selected" at 340,265
button "loadpage" hide

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
      gosub loadpage
      break
    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

UNTIL BUTTON_PRESSED("close")

page "main" set

gosub showbuttons

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

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 »

I have resized the buttons and added "Copy URL" by which current URL is copied to clipboard for usage in e.g. e-mail.

Code: Select all

'Dav's Browser
'==========================
'Simple web browser - v1.06
'==========================
'A simple web browser for smart Basic.
'Uses javascript for browsing functions.
'Has a basic bookmark manager.
'Coded by Dav , FEB/2015
'
'NEW: Added bookmark manager page.
'     You can now add/delete bookmarks.
'     Bookmarks saved in file in current
'     directory named: 'bookmarks.ini'

'NOTE: Homepage is set to google.com.
'      You can change this by changing
'      the home$ variable.

option base 1

page "main" set

'init screen
graphics clear 1,1,1
set toolbar off

set browsers scaled 'allow zooming in/out

'get current screen width
curwidth= screen_width()

'load the homepage
home$="http://www.google.com" 'homepage...
url$=home$
gosub loadpage   'load homepag

'make buttons
Buttons=9
DIM Button$(buttons,4)
fs=14 'font size
SET BUTTONS FONT SIZE fs
ButtonsData:'ID,txt,x,y
DATA "back","<",10, 3
DATA "forward",">",3*fs, 3
DATA "stop","Stop",6*fs,3
DATA "reload","Reload",10*fs,3
DATA "home","Home",15*fs,3
DATA "bookmarks","Bookmarks",20*fs,3
DATA "url","Enter URL",27*fs,3
DATA "copy","Copy URL",34*fs,3
DATA "quit","Quit",50*fs,3
GOSUB LoadButtons
CALL MakeButtons

'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("copy") then
   gosub CopyURL
 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
gosub DeleteButtons
end


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

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

browser "n" url url$ at 0,40 size screen_width(),screen_height() -40
return

'-------
LoadButtons:
'-------
RESTORE TO ButtonsData
FOR i=1 to Buttons
  FOR j=1 to 4
    READ Button$(i,j)
  NEXT j
NEXT i
RETURN

'-------
DEF MakeButtons
'-------
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) text .Button$(i,2) AT .Button$(i,3),.Button$(i,4)
  NEXT i
END DEF

'-------
DeleteButtons:
'-------
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) DELETE
  NEXT i
RETURN

'----------
hidebuttons:
'----------
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) HIDE
  NEXT i
return

'----------
showbuttons:
'----------
  FOR i=1 TO .Buttons
    BUTTON .Button$(i,1) SHOW
  NEXT i
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


'-------
CopyURL:
'-------
  CLIPBOARD CLEAR
  U$=browser_text$("n", "window.location.href")
  CLIPBOARD WRITE U$
RETURN

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

gosub loadbookmarks

'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,50

showbookmarks:

LIST bm$ TEXT list$(1) AT 2,2 SIZE 595,260
LIST bm$ SET TEXT list$

BUTTON "close" text "close" AT 525,265

button "addpage" text "Add Current" at 20,265
button "deletepage" text "Delete Selected" at 160,265
button "deletepage" hide
button "loadpage" text "Load Selected" at 340,265
button "loadpage" hide

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
      gosub loadpage
      break
    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

UNTIL BUTTON_PRESSED("close")

page "main" set

gosub showbuttons

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
20150213 CopyURL modified to v1.06 with code posted by Dav » 13 Feb 2015, 01:35
Last edited by Dutchman on Fri Feb 13, 2015 11:42 am, edited 2 times in total.

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 »

Nice addition, Dutchman. I like it! Here's something I tried yesterday to clear the screen and show finished when quitting. It seems to work ok. I added it when program ends.

Code: Select all

Page bm$ hide
Page "main" hide

End
Is there a way to resize the browser window without updating the data in it? When I turn the iPad and re-call the browser window, it has to reload the page. Like typing this now, if I turn the iPad all my text would all be removed. It would be helpful to resize it without having to reload the page. I like how sprites can be resized, maybe a browser way too? Like Browser "n" resize x,y

I have been considering what Mr. Kibernetik said about programs running also on iPhone and I'd like to make this work on iPhone too. I'm going to try and redesign it to run on iPhone. But I don't have iPhone to test on. Is the only difference in iPad & iPhone the screen size?

- Dav

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 »

Dav wrote:I'd like to make this work on iPhone too. I'm going to try and redesign it to run on iPhone. But I don't have iPhone to test on. Is the only difference in iPad & iPhone the screen size?
Yes.

The main approach I see is to make buttons shorter by using special symbols instead of text. For example:
◼︎ ▶︎ ◀︎ ↺ ↲ ★ ⚑

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 »

Thank you! I'll get working on it. :)

- Dav

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 »

Dutchman wrote:I have resized the buttons and added "Copy URL" by which current URL is copied to clipboard for usage in e.g. e-mail.
Hi Dutchman. The CopyURL you added is very useful. I have found that copying the url$ to clipboard may not save the current page the browser has navigated to, but only the last url$ variable sent the the loadpage routine. So I have change mine to this which saves the current url:

Code: Select all

'-------
CopyURL:
'-------
  CLIPBOARD CLEAR
  U$=browser_text$("n", "window.location.href")
  CLIPBOARD WRITE U$
RETURN


I also edited my original code to do this when adding bookmark and when resizing the browser with the right url again.

- 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 »

Thanks Dav.
I copied your new version 1.05, but CopyURL is not in that version.
So I have updated my previous version to 1.06 with your correction.

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 bookmarks (iPad/iPhone/iPod touch)

Post by Dav »

I have altered the simple browser to now work with iPhone & iPod touch as well as iPad. I fixed a couple of things and tweaked the layout to make it easier to navigate (bigger buttons). On iPhone, only symbols are used in menu. The bookmark manager resizes if screen is rotated, like the browser window does. You can use this new browser code with any previous bookmarks.ini file, it will not erase your previously saved bookmarks.

Code in first post has been updated with the new version, and a new screenshot is attached.

dutchman: I see now that I forgot to add your CopyURL to this new version, I will try to update again with it included.

- Dav

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

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

Post by rbytes »

This is a great browser, and very fast. I will use it a lot. Thanks!
The only thing that gets me down is gravity...

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 bookmarks (iPad/iPhone/iPod touch)

Post by Dav »

I have posted an update to this simple browser in the first post - now v1.08.

Added an infobar at top to show connection status, time & battery level. Added a field to display current url. The url display is a field that you can select the text to copy current url to clipboard. I also changed the bookmarks menu to drop down & rise up out of sight (animated).

Posted new screenshots of what it looks like on my devices.

- Dav

Post Reply