Didier Posted May 15, 2018 Share Posted May 15, 2018 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 More sharing options...
Sherzod Posted May 15, 2018 Share Posted May 15, 2018 Hi, I have a TUniURLFrame (wbSearchAnnonce).I just do : wbSearchAnnonce.url := mypage mypage - what is this URL? Link to comment Share on other sites More sharing options...
Didier Posted May 15, 2018 Author Share Posted May 15, 2018 just one url like https://www.google.fr/ Link to comment Share on other sites More sharing options...
Sherzod Posted May 15, 2018 Share Posted May 15, 2018 just one url like https://www.google.fr/ Well, this URL will not open at all Link to comment Share on other sites More sharing options...
Didier Posted May 15, 2018 Author Share Posted May 15, 2018 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 More sharing options...
delagoutte Posted May 17, 2018 Share Posted May 17, 2018 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 More sharing options...
Oliver Morsch Posted May 17, 2018 Share Posted May 17, 2018 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 More sharing options...
delagoutte Posted May 18, 2018 Share Posted May 18, 2018 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 More sharing options...
Oliver Morsch Posted May 18, 2018 Share Posted May 18, 2018 "Access-Control-Allow-Origin" is for XHR. If you use subdomains you can use <script>document.domain = 'example.com'</script> for sub1.example.com and sub2.example.com. See here. And here are additional informations: https://benohead.com/cross-document-communication-with-iframes/ Link to comment Share on other sites More sharing options...
Didier Posted May 21, 2018 Author Share Posted May 21, 2018 Thank you, I'll try to do from this way. Link to comment Share on other sites More sharing options...
Didier Posted May 22, 2018 Author Share Posted May 22, 2018 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 More sharing options...
Recommended Posts