Jump to content

uniurlframe get html


Didier

Recommended Posts

hello,

 

I have a TUniURLFrame (wbSearchAnnonce).

I just do : wbSearchAnnonce.url := mypage

 

but i don't know how to get the html code.

 

i ve done :

procedure TFrameDossier.wbSearchAnnonceFrameLoaded(Sender: TObject);
begin
  UniSession.AddJS('ajaxRequest('+wbSearchAnnonce.JSName + ',"gethtml" , ["_value="+document.getElementsByName("html").innerHTML])');
end;

 

procedure TFrameDossier.wbSearchAnnonceAjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  FSourceHtml := '123';

  if EventName='gethtml' then
  begin
    FSourceHtml :=Params.Values['_value'];
    if FSourceHtml<>'' then
      UniSession.AddJS('alert("Custom JS Code") ' + FSourceHtml)
    else
      UniSession.AddJS('alert("Vide")')
  end;
end;

 

But FSourceHtml is allways at 'undefined'

 

 

Can you help me please ?

Link to comment
Share on other sites

It's not the problem of the url.

You can go at any you want.

if '.fr' don't work for you, try for exemple 'https://www.google.com'

 

But in my application, customers can navigate, so url will change.

when he click on a button, i must parse the html to find some words a search.

So my problem is how to have the html text.

Link to comment
Share on other sites

i think Didier would like to have a method for sending the html source code of a page that is loaded in a UniUrlFrame to the App unigui.

 

for example, open the sample of unigui desktop "URLFrame" , launch the app,  navigate to an adress in the app -> how to recover the html source code that is contained in the uniUrlFrame1 ? and how send it to the main app ?

Link to comment
Share on other sites

i think Didier would like to have a method for sending the html source code of a page that is loaded in a UniUrlFrame to the App unigui.

 

for example, open the sample of unigui desktop "URLFrame" , launch the app,  navigate to an adress in the app -> how to recover the html source code that is contained in the uniUrlFrame1 ? and how send it to the main app ?

 

UniUrlFrame uses an iFrame. And the browser prevents accessing an iframe, when it conflicts with the "same origin policy". This is for security in web (XSS, ...). So you can't get the html code.

Link to comment
Share on other sites

And if we control the both webserver that are on two domain (one for unigui app and the other for the page in iframe), is it possible ? could we configure server or app for having this possibility ?

i try adding Access-Control-Allow-Origin: * in the header but without success. but maybe i don't do it with the good method.

Link to comment
Share on other sites

Hi,

It  doesn't work ;). Maybe i do something wrong...

 

So i'll go to the same page like this to have the html text :

function GetUrlContent(const Url: string): string;
var
  NetHandle: HINTERNET;
  UrlHandle: HINTERNET;
  Buffer: array[0..1023] of byte;
  BytesRead: dWord;
  StrBuffer: UTF8String;
begin
  Result := '';
  NetHandle := InternetOpen('Delphi 2009', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if Assigned(NetHandle) then
    try
      UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
      if Assigned(UrlHandle) then
        try
          repeat
            InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
            SetString(StrBuffer, PAnsiChar(@Buffer[0]), BytesRead);
            Result := Result + StrBuffer;
          until BytesRead = 0;
        finally
          InternetCloseHandle(UrlHandle);
        end
      else
        raise Exception.CreateFmt('Cannot open URL %s', [Url]);
    finally
      InternetCloseHandle(NetHandle);
    end
  else
    raise Exception.Create('Unable to initialize Wininet');
end;

Thank you for your answers

Link to comment
Share on other sites

×
×
  • Create New...