Go to anchor in WebGadget [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Go to anchor in WebGadget [Resolved]

Post by Kwai chang caine »

Hello at all :D

I try to go to an anchor in a web page into a webgadget , but with a button
I have try with JavaScript, but that not works
Surelly my code javascript is not good, or perhaps it's not possible like this.
All method interested me :D

Code: Select all

Enumeration
  #Form0
  #Web0
  #BoutonGoto50
EndEnumeration

OpenWindow(#Form0, 664, 253, 411, 451, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
WebGadget(#Web0, 14, 20, 384, 401, "")
ButtonGadget(#BoutonGoto50, 50, 428, 315, 20, "Goto to anchor 50")

Html$ = "<!DOCTYPE HTML PUBLIC " + Chr(34) + "-//W3C//DTD HTML 4.01 Transitional//EN" + Chr(34) + ">" + #CRLF$
Html$ + "<html>" + #CRLF$
Html$ + " <head>" + #CRLF$
Html$ + " <title>Document sans titre</title>" + #CRLF$
Html$ + " <meta http-equiv=" + Chr(34) + "Content-Type" + Chr(34) + " content=" + Chr(34) + "text/html; charset=iso-8859-1" + Chr(34) + ">" + #CRLF$
Html$ + #CRLF$
Html$ + " </head>" + #CRLF$
Html$ + #CRLF$
Html$ + " <body>" + #CRLF$
Html$ + #CRLF$
      
For i = 1 To 60
 
 Html$ + "<a href=#Kcc" + Trim(Str(i)) + ">I'm KCC line number " + Trim(Str(i)) + "<br><br><br></a></body>" + #CRLF$
 
Next

Html$ + " </body>" + #CRLF$
Html$ + "</html>" + #CRLF$
SetGadgetItemText(#Web0, #PB_Web_HtmlCode, Html$)

Repeat
  
 Evenement = WaitWindowEvent()
 
 If Evenement = #PB_Event_Gadget
  
  Select EventGadget()
    
   Case #BoutonGoto50
   
    GoAnchor$ = "<!DOCTYPE HTML PUBLIC " + Chr(34) + "-//W3C//DTD HTML 4.01 Transitional//EN" + Chr(34) + ">" + #CRLF$
    GoAnchor$ + "<html>" + #CRLF$
    GoAnchor$ + " <head>" + #CRLF$
    GoAnchor$ + " <title>Document sans titre</title>" + #CRLF$
    GoAnchor$ + " <meta http-equiv=" + Chr(34) + "Content-Type" + Chr(34) + " content=" + Chr(34) + "text/html; charset=iso-8859-1" + Chr(34) + ">" + #CRLF$
    GoAnchor$ + #CRLF$
    GoAnchor$ + " </head>" + #CRLF$
    GoAnchor$ + #CRLF$
    GoAnchor$ + " <body>" + #CRLF$
    GoAnchor$ + #CRLF$
    GoAnchor$ + "<script language=javascript>"
    GoAnchor$ + "gotourl(" + Chr(34) + "#Kcc50" + Chr(34) + " );"
    GoAnchor$ + "</script>"
    GoAnchor$ + " </body>" + #CRLF$
    GoAnchor$ + "</html>" + #CRLF$
    SetGadgetItemText(#Web0, 0, GoAnchor$)
     
  EndSelect  
  
 EndIf 
 
Until Evenement = #PB_Event_CloseWindow
Have a good day
Last edited by Kwai chang caine on Sat Feb 15, 2014 6:09 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Go to anchor in WebGadget

Post by Kwai chang caine »

I move...i have found a way with a Temp HTML file (In fact i have an error in the HTML code above :oops:)
But is it possible, to have the same thing, without creating a file ??

Code: Select all

Enumeration
  #Form0
  #Web0
  #BoutonGoto50
EndEnumeration

OpenWindow(#Form0, 664, 253, 411, 451, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
WebGadget(#Web0, 14, 20, 384, 401, "")
ButtonGadget(#BoutonGoto50, 50, 428, 315, 20, "Goto to anchor 50")

Html$ = "<!DOCTYPE HTML PUBLIC " + Chr(34) + "-//W3C//DTD HTML 4.01 Transitional//EN" + Chr(34) + ">" + #CRLF$
Html$ + "<html>" + #CRLF$
Html$ + " <head>" + #CRLF$
Html$ + " <title>Document sans titre</title>" + #CRLF$
Html$ + " <meta http-equiv=" + Chr(34) + "Content-Type" + Chr(34) + " content=" + Chr(34) + "text/html; charset=iso-8859-1" + Chr(34) + ">" + #CRLF$
Html$ + #CRLF$
Html$ + " </head>" + #CRLF$
Html$ + #CRLF$
Html$ + " <body>" + #CRLF$
Html$ + #CRLF$
      
For i = 1 To 60
 
 Html$ + "<div id=" + Chr(34) + "Kcc" + Trim(Str(i)) + Chr(34) + ">I'm KCC line number " + Trim(Str(i)) + "<br><br><br></div></body>" + #CRLF$
 
Next

Html$ + " </body>" + #CRLF$
Html$ + "</html>" + #CRLF$

If FileSize("c:\TempPage.html") <> -1
 DeleteFile("c:\TempPage.html")
EndIf

Canal = CreateFile(#PB_Any, "c:\TempPage.html")
WriteString(Canal, Html$)
CloseFile(Canal)

SetGadgetText(#Web0, "file:///" + "c|/TempPage.html")

Repeat
  
 Evenement = WaitWindowEvent()
 
 If Evenement = #PB_Event_Gadget
  
  Select EventGadget()
    
   Case #BoutonGoto50
       
    SetGadgetText(#Web0, "file:///" + "c|/TempPage.html#Kcc50")
     
  EndSelect  
  
 EndIf 
 
Until Evenement = #PB_Event_CloseWindow

If FileSize("c:\TempPage.html") <> -1
 DeleteFile("c:\TempPage.html")
EndIf
ImageThe happiness is a road...
Not a destination
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Go to anchor in WebGadget

Post by Sparkie »

Hi KCC :D

There are other ways but I make use of the element id name.

Code: Select all

Enumeration
  #Form0
  #Web0
  #BoutonGoto50
EndEnumeration

OpenWindow(#Form0, 664, 253, 411, 451, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
WebGadget(#Web0, 14, 20, 384, 401, "")
ButtonGadget(#BoutonGoto50, 50, 428, 315, 20, "Goto to anchor 50")

Html$ = "<!DOCTYPE HTML PUBLIC " + Chr(34) + "-//W3C//DTD HTML 4.01 Transitional//EN" + Chr(34) + ">" + #CRLF$
Html$ + "<html>" + #CRLF$
Html$ + " <head>" + #CRLF$
Html$ + " <title>Document sans titre</title>" + #CRLF$
Html$ + " <meta http-equiv=" + Chr(34) + "Content-Type" + Chr(34) + " content=" + Chr(34) + "text/html; charset=iso-8859-1" + Chr(34) + ">" + #CRLF$
Html$ + #CRLF$
Html$ + " </head>" + #CRLF$
Html$ + #CRLF$
Html$ + " <body>" + #CRLF$
Html$ + #CRLF$
      
For i = 1 To 60
 ;***************** add the id attribute to each hash *******************
 Html$ + "<a id='#KCC" + Str(i) + "'>I'm KCC line number " + Trim(Str(i)) + "<br><br><br></a></body>" + #CRLF$
 
Next

Html$ + " </body>" + #CRLF$
Html$ + "</html>" + #CRLF$
SetGadgetItemText(#Web0, #PB_Web_HtmlCode, Html$)

Repeat
  
 Evenement = WaitWindowEvent()
 
 If Evenement = #PB_Event_Gadget
  
  Select EventGadget()
    
    Case #BoutonGoto50
    GoAnchor$ = "javascript:ele = document.getElementById('#KCC50');"
    GoAnchor$ + "ele.scrollIntoView();"
    SetGadgetText(#Web0, GoAnchor$)
     
  EndSelect  
  
 EndIf 
 
Until Evenement = #PB_Event_CloseWindow
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Go to anchor in WebGadget

Post by Kwai chang caine »

Yeeeessssss !!!!!! :D :D
That's works perfectly !!!!!!!

Thanks ...to continue to help your old earthworms of the programming !!!!
Image

And mainly thanks a lot, MASTER SPARKIE to give me the amazing pleasure, of come back with us.
You missed so much, during these years :cry:, at your "assistant" :oops:

Image (Remember :wink:)

I hope, you never go away, another big time like this, of your second familly :D

Long life to you, long life to the USA !!!

Image

Have a very good Week-End MASTER 8)
ImageThe happiness is a road...
Not a destination
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Go to anchor in WebGadget [Resolved]

Post by davido »

Hi KCC
Pure magic :)
DE AA EB
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Go to anchor in WebGadget [Resolved]

Post by Kwai chang caine »

Thanks DAVIDO 8) :D
Nothing is too much for PB and his numerous powerfull MASTER users :wink:
ImageThe happiness is a road...
Not a destination
Post Reply