Forum > General
how to use "user agent" in webbrowser (IE) mobile mode
Ericktux:
hello brothers I found this example of webbrowser (IE) called "myBrowser.zip" in the following link
https://www.lazarusforum.de/viewtopic.php?f=55&t=7407
At the moment it works and compiles perfectly, it's very basic, just what I needed.
but I would like to modify the "user agent" to be able to emulate the mobile mode of the web pages. The problem is that I don't know what to do.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---'User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53'
I need your help please. :(
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, activexcontainer, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, SHDocVw_1_1_TLB; type { TForm1 } TForm1 = class(TForm) ActiveXContainer1: TActiveXContainer; btnTest: TButton; btnNavigate: TButton; btnPrint: TButton; btnBack: TButton; btnForward: TButton; brnRefresh: TButton; btnStop: TButton; edtUrl: TEdit; lblStatus: TLabel; pnlFunctions: TPanel; pnlStatus: TPanel; procedure brnRefreshClick(Sender: TObject); procedure btnBackClick(Sender: TObject); procedure btnNavigateClick(Sender: TObject); procedure btnForwardClick(Sender: TObject); procedure btnPrintClick(Sender: TObject); procedure btnStopClick(Sender: TObject); procedure btnTestClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private procedure OnStatusTextChange(Sender: TObject; Text_: WideString); public { public declarations } end; var Form1: TForm1; Browser: TEvsWebBrowser; implementation {$R *.lfm} { TForm1 } procedure TForm1.btnTestClick(Sender: TObject);var ovMIMEType, ovDocument: Olevariant;begin ovDocument := Browser.ComServer.Document; ovMIMEType := 'text/html'; ovDocument.Open(ovMIMEType); ovDocument.Write('<html><body><p>Hello World!</p></body></html>'); ovDocument.Close();end; procedure TForm1.btnNavigateClick(Sender: TObject);var ovNull, ovUrl: OleVariant;begin ovUrl := Utf8decode(edtUrl.Text); ovNull := NULL; Browser.ComServer.Navigate2(ovUrl, ovNull, ovNull, ovNull, ovNull);end; procedure TForm1.btnForwardClick(Sender: TObject);begin Browser.ComServer.GoForward;end; procedure TForm1.btnBackClick(Sender: TObject);begin Browser.ComServer.GoBack;end; procedure TForm1.brnRefreshClick(Sender: TObject);begin Browser.ComServer.Refresh;end; procedure TForm1.btnPrintClick(Sender: TObject);var ovIn, ovOut: OleVariant;begin if (Browser.ComServer.QueryStatusWB(OLECMDID_PRINT) and OLECMDF_ENABLED) = 2 then Browser.ComServer.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, ovIn, ovOut);end; procedure TForm1.btnStopClick(Sender: TObject);begin Browser.ComServer.Stop;end; procedure TForm1.FormCreate(Sender: TObject);var ovUrl, ovNull: Olevariant;begin Browser := TEvsWebBrowser.Create(Self); ActiveXContainer1.ComServer := Browser.ComServer; ActiveXContainer1.Active := true; Browser.OnStatusTextChange := @OnStatusTextChange; ovUrl := Utf8decode('about:blank'); ovNull := NULL; Browser.ComServer.Navigate2(ovUrl, ovNull, ovNull, ovNull, ovNull); Browser.ComServer.Silent := true;end; procedure TForm1.FormDestroy(Sender: TObject);begin Browser.Free;end; procedure TForm1.OnStatusTextChange(Sender: TObject; Text_: WideString);begin lblStatus.Caption:='Browser: '+UTF8Encode(Text_);end; end.
I attach the project and main code
KodeZwerg:
Doing this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.btnNavigateClick(Sender: TObject);var ovNull, ovUrl, ovHeader: OleVariant; s: AnsiString;begin ovUrl := Utf8decode(edtUrl.Text); ovNull := NULL; s := 'User-Agent: Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53'#0#0; ovHeader := PAnsiChar(s); Browser.ComServer.Navigate2(ovUrl, ovNull, ovNull, ovNull, ovHeader);end;End up like i show in attachment.
KodeZwerg:
--- Quote from: Ericktux on December 07, 2022, 05:59:44 am ---but I would like to modify the "user agent" to be able to emulate the mobile mode of the web pages.
--- End quote ---
Changing the user agent does not affect how it is rendered.
Ericktux:
hello friend, thank you very much for your help, it works fine, but the web does not detect the change :(, for example, I am trying to make an app to download the windows 10 iso from its official website here
https://www.microsoft.com/es-es/software-download/windows10ISO
If I open "Internet explorer" and change its "user agent" it is possible to enter the web in mobile mode and download the iso. but I can't do that with the project.
please help :( :(
attached image example
KodeZwerg:
--- Quote from: Ericktux on December 07, 2022, 03:53:55 pm ---hello friend, thank you very much for your help, it works fine
--- End quote ---
You are welcome O:-)
--- Quote from: Ericktux on December 07, 2022, 03:53:55 pm ---but the web does not detect the change
--- End quote ---
That I told, it does not change the way of how its rendered.
Navigation
[0] Message Index
[#] Next page