WebGadget disable JavaScript

Just starting out? Need help? Post your questions and find answers here.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

WebGadget disable JavaScript

Post by VB6_to_PBx »

How can i disable JavaScript in WebGadget ??

FireFox v19.0.2 lets me have Option to [•] disable JavaScript

i'd like to do same thing in PureBasic's WebGadget
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: WebGadget disable JavaScript

Post by VB6_to_PBx »

anyone know how to disable JavaScript in PureBasic's WebGadget ??
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
linnar
New User
New User
Posts: 2
Joined: Sun Oct 05, 2014 9:21 am

Re: WebGadget disable JavaScript

Post by linnar »

I have the same question!

Have a code that loads web pages but I keep getting an error message window from Windows:
"An error has occurred in the script on this page!"

I do not want the window to be opened. Anyone know how it's done?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: WebGadget disable JavaScript

Post by PB »

> "An error has occurred in the script on this page"

I've been using this for years to prevent the above message.
It's not originally my code, but I put it in an easy procedure.

Code: Select all

Procedure HideWebGadgetErrors(gad)
  SetGadgetAttribute(gad,#PB_Web_BlockPopups,#True)
  id.IWebBrowser2=GetWindowLongPtr_(GadgetID(gad),#GWL_USERDATA)
  id\put_Silent(#True) ; Suppress JavaScript error messages.
EndProcedure
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
falsam
Enthusiast
Enthusiast
Posts: 632
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: WebGadget disable JavaScript

Post by falsam »

silent script and html5 compatible browser. I changed the browser emulation (Code 11001 :Internet Explorer 11)

Code: Select all

RegCreateKeyValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", GetFilePart(ProgramFilename()), "11001", #REG_DWORD, ".")
This link for other browser emulation http://msdn.microsoft.com/en-us/library ... s.85).aspx

Code: Select all

;WebGadget HTML5 compatible
;Contributor: Sphere Users Pure Basic
;
;Create 29-08-2014
;Update 29-08-2014
;

Enumeration Window
  #MainForm
EndEnumeration

Enumeration Gadget
  #URL
  #WebGadget
EndEnumeration

Global Url.s="http://html5test.com/"

;-
;- U.T. Registry
Procedure RegConvertRegKeyToTopKeyAndKeyName(Key.s)
  
  Shared topKey,KeyName.s
  
  temp.s=StringField(Key,1,"\")
  temp=UCase(temp)
  Select temp
    Case "HKEY_CLASSES_ROOT"
      topKey=#HKEY_CLASSES_ROOT
    Case "HKEY_CURRENT_USER"
      topKey=#HKEY_CURRENT_USER
    Case "HKEY_LOCAL_MACHINE"
      topKey=#HKEY_LOCAL_MACHINE
    Case "HKEY_USERS"
      topKey=#HKEY_USERS 
    Case "HKEY_CURRENT_CONFIG"
      topKey=#HKEY_CURRENT_CONFIG 
  EndSelect
  
  PositionSlash=FindString(Key,"\",1)
  KeyName.s=Right(Key,(Len(Key)-PositionSlash))
  
EndProcedure

ProcedureDLL RegSetValue(Key.s, ValueName.s, Value.s, Type, ComputerName.s) ; Sets a Value
  
  ;Type can be #REG_SZ / #REG_DWORD / #REG_BINARY / #REG_EXPAND_SZ
  ;For REG_BINARY type use Hexa value as String
  ;Returns 1 if successful or 0 if it fails
  
  Shared RegWow64.l,RegEx,topKey,KeyName.s
  RegConvertRegKeyToTopKeyAndKeyName(Key)
  
  If ComputerName = "."
    If RegEx
      GetHandle = RegOpenKeyEx_(topKey,KeyName,0,#KEY_ALL_ACCESS|RegWow64,@hKey) 
    Else
      GetHandle = RegOpenKey_(topKey,KeyName,@hKey) 
    EndIf
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName,topKey,@lhRemoteRegistry) 
    If RegEx
      GetHandle = RegOpenKeyEx_(lhRemoteRegistry,KeyName,0,#KEY_ALL_ACCESS|RegWow64,@hKey) 
    Else
      GetHandle = RegOpenKey_(lhRemoteRegistry,KeyName,@hKey) 
    EndIf
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    lpcbData = 255 
    lpData.s = Space(255) 
    
    Select Type 
        
      Case #REG_EXPAND_SZ 
        GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_EXPAND_SZ, @Value, Len(Value) + 1) 
        
      Case #REG_SZ 
        GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_SZ, @Value, Len(Value) + 1) 
        
      Case #REG_DWORD 
        lValue = Val(Value) 
        GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_DWORD, @lValue, 4) 
        
      Case #REG_BINARY
        LenBuffer=Len(Value)/2
        *RegBuffer=AllocateMemory(LenBuffer)
        For n=0 To LenBuffer-1
          OctetHexa.s=Mid(Value,(n*2)+1,2)
          Octet=Val("$"+OctetHexa)
          PokeB(*RegBuffer+n,Octet)
        Next
        GetHandle= RegSetValueEx_(hKey,ValueName,0,#REG_BINARY,*RegBuffer,LenBuffer) 
        FreeMemory(*RegBuffer)
        
    EndSelect 
    
    RegCloseKey_(hKey) 
    ergebnis = 1 
    ProcedureReturn ergebnis 
  Else 
    RegCloseKey_(hKey) 
    ergebnis = 0 
    ProcedureReturn ergebnis 
  EndIf 
EndProcedure 

ProcedureDLL RegCreateKey(Key.s, ComputerName.s)
  
  ;It create subkey if KeyPath don't exist
  ;Returns 1 if successful or 0 if it fails
  
  Shared RegWow64.l,RegEx,topKey,KeyName.s
  
  RegConvertRegKeyToTopKeyAndKeyName(Key)  
  lpSecurityAttributes.SECURITY_ATTRIBUTEs 
  
  If ComputerName = "."
    If RegEx
      GetHandle = RegCreateKeyEx_(topKey,KeyName,0,0,#REG_OPTION_NON_VOLATILE,#KEY_ALL_ACCESS|RegWow64,@lpSecurityAttributes,@hNewKey,@GetHandle)
    Else
      GetHandle = RegCreateKey_(topKey,KeyName,@hNewKey)
    EndIf
  Else 
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry) 
    If RegEx
      GetHandle = RegCreateKeyEx_(lhRemoteRegistry,KeyName,0,0,#REG_OPTION_NON_VOLATILE,#KEY_ALL_ACCESS|RegWow64,@lpSecurityAttributes,@hNewKey,@GetHandle)
    Else
      GetHandle = RegCreateKey_(lhRemoteRegistry,KeyName,@hNewKey) 
    EndIf
  EndIf 
  
  If GetHandle = #ERROR_SUCCESS 
    GetHandle = RegCloseKey_(hNewKey) 
    CreateKey = #True 
  Else 
    CreateKey = #False 
  EndIf 
  ProcedureReturn CreateKey 
EndProcedure 

ProcedureDLL RegCreateKeyValue(Key.s,ValueName.s,Value.s,Type,ComputerName.s) ; Creates a Key and a Value in a Single Command
  
  ;Type can be #REG_SZ or #REG_DWORD
  ;Returns 1 if successful or 0 if it fails
  
  RegCreateKey(Key,ComputerName) 
  ProcedureReturn RegSetValue(Key,ValueName,Value,Type,ComputerName) 
EndProcedure 

;-
;-Test Area
Procedure NavigationCallback(Gadget, NewUrl.s) 
  Debug "new " + NewUrl + " - " + "old " + Url
  
  If NewUrl <> Url
    SetGadgetText(Gadget, NewUrl)
    Url = NewUrl  
  EndIf
  
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure 

Procedure MainFormShow()
  OpenWindow(#MainForm, 0, 0, 1024, 768,"WebGadget HTML5 compatible",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  WebGadget(#WebGadget, 0, 0, 1024, 768, Url)   
  ;SetGadgetAttribute(#WebGadget, #PB_Web_NavigationCallback, @NavigationCallback())  
  SetGadgetAttribute(#WebGadget, #PB_Web_BlockPopups, #True)  
  SetGadgetAttribute(#WebGadget, #PB_Web_BlockPopupMenu, #True)
  
  myBrowser.IWebBrowser2 = GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)
  myBrowser\put_Silent(#True) ;Suppress error warnings in WebGadget
  myBrowser\put_Left(0) 
EndProcedure

Procedure Start()
  RegCreateKeyValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", GetFilePart(ProgramFilename()), "11001", #REG_DWORD, ".")
  MainFormShow()  
EndProcedure

Start()

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
linnar
New User
New User
Posts: 2
Joined: Sun Oct 05, 2014 9:21 am

Re: WebGadget disable JavaScript

Post by linnar »

Thanks for your nice tips. I will test them soon.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: WebGadget disable JavaScript

Post by bbanelli »

falsam wrote:silent script and html5 compatible browser. I changed the browser emulation (Code 11001 :Internet Explorer 11)
Fantastic!

This is why I asked for "Thank you"/"Karma" on forum! :)
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: WebGadget disable JavaScript

Post by bbanelli »

Greetings,

how come WebGadget on Windows 10 with code from above reports as IE 11 (@W8) and has 50 points less than Edge?

Image
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Post Reply