2012-02-12 10 views
5

मैं अपने डेल्फी 6 एप्लिकेशन में क्रोमियम वेब ब्राउज़र नियंत्रण का उपयोग कर रहा हूं।उपयोगकर्ता के डिफ़ॉल्ट वेब ब्राउज़र को लॉन्च करते समय क्रोमियम को "WebViewHost" होस्ट विंडो बनाने से कैसे रोक सकता हूं?

जब भी उपयोगकर्ता वर्तमान में प्रदर्शित होने वाले वेब पेज पर एक वेब लिंक पर क्लिक करता है जो कि मेरी प्राथमिक वेबसाइट पर नहीं है, तो मैंने विंडोज शैलएक्सक्यूट() फ़ंक्शन का उपयोग करके URL खोलकर URL के साथ अपना डिफ़ॉल्ट वेब ब्राउज़र लॉन्च किया है। 'ओपन' क्रिया। मैं इसे BeforeBrowse() ईवेंट हैंडलर से करता हूं और साथ ही नेविगेशन को रद्द करता हूं।

दूसरे शब्दों में, मैं क्रोमियम नियंत्रण में बाहरी यूआरएल नहीं दिखाता लेकिन इसके बजाय, उन्हें उपयोगकर्ता के डिफ़ॉल्ट वेब ब्राउज़र में दिखाएं।

यह ठीक काम करता है लेकिन कभी-कभी मुझे अपने आवेदन के स्वामित्व वाली स्टैंड-अलोन विंडो पॉप अप भी मिलती है और इसमें लगभग आधा स्क्रीन होती है जो पूरी तरह से खाली होती है (मेरे विंडोज थीम के साथ खाली सफेद क्लाइंट क्षेत्र)। विंडो का विंडोज क्लास नाम "webviewhost" है।

क्या कोई मुझे बता सकता है कि इस "भूत" विंडो को दबाने के लिए कैसे?

उत्तर

7

यहां समस्या पॉपअप विंडो के साथ है। वे OnBeforeBrowse ईवेंट से पहले बनाए गए हैं और आप उनकी नेविगेशन रद्द कर देते हैं ताकि वे भूत की तरह दिख सकें।

आप OnBeforePopup ईवेंट के परिणाम को सही पर सेट करके अपनी रचना को रोक सकते हैं, लेकिन यह नेविगेशन समाप्त हो जाएगा ताकि OnBeforeBrowse निकाल दिया नहीं जाएगा। यदि आप इस तरह का पालन करते हैं तो आपको OnBeforePopup ईवेंट में भी अपनी ShellExecute कार्रवाई करना होगा।

procedure TForm1.Chromium1BeforePopup(Sender: TObject; 
    const parentBrowser: ICefBrowser; var popupFeatures: TCefPopupFeatures; 
    var windowInfo: TCefWindowInfo; var url: ustring; var client: ICefBase; 
    out Result: Boolean); 
begin 
    // you can set the Result to True here and block the window creation at all, 
    // but then you will stop also the navigation and the OnBeforeBrowse event 
    // won't be fired, so if you will follow this way then you'll have to perform 
    // your ShellExecute action here as well 

    if url <> 'http://www.yourdomain.com' then 
    begin 
    Result := True; 
    ShellExecute(Handle, 'open', PChar(url), '', '', SW_SHOWNORMAL); 
    end; 
end; 

एक और तरीका है OnBeforePopup स्थिति में सही पर m_bWindowRenderingDisabled ध्वज सेट करने के लिए क्या बनाया जाना (ceflib.pas में वर्णित के रूप आधिकारिक दस्तावेज, खिड़की बनाया है, लेकिन छिपा रहता है IMHO में नहीं, पॉप अप विंडो को रोकने चाहिए , और मुझे उम्मीद है कि इससे कोई रिसाव नहीं होगा, सत्यापित नहीं किया है) और नेविगेशन जारी रहेगा ताकि OnBeforePopup ईवेंट निकाल दिया जाएगा।

procedure TForm1.Chromium1BeforePopup(Sender: TObject; 
    const parentBrowser: ICefBrowser; var popupFeatures: TCefPopupFeatures; 
    var windowInfo: TCefWindowInfo; var url: ustring; var client: ICefBase; 
    out Result: Boolean); 
begin 
    // you can set the m_bWindowRenderingDisabled flag to True here what should 
    // prevent the popup window to be created and since we don't need to take 
    // care about substitute parent for popup menus or dialog boxes of this popup 
    // window (because we will cancel the navigation anyway) we don't need to set 
    // the WndParent member here; but please check if there are no resource leaks 
    // with this solution because it seems more that the window is just hidden 

    if url <> 'http://www.yourdomain.com' then 
    windowInfo.m_bWindowRenderingDisabled := True; 
end; 

निम्नलिखित कोड अपनी समस्या का अनुकरण है (यदि आप पर क्लिक करें पॉप अप विंडो खुल जाएगा this tutorial उदाहरण के रूप में इस्तेमाल में पृष्ठ के निचले हिस्से में लिंक my popup है)।

uses 
    ShellAPI, ceflib, cefvcl; 

const 
    PageURL = 'http://www.htmlcodetutorial.com/linking/linking_famsupp_72.html'; 
    PopupURL = 'http://www.htmlcodetutorial.com/linking/popupbasic.html'; 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    Chromium1.Load(PageURL); 
end; 

procedure TForm1.Chromium1BeforeBrowse(Sender: TObject; 
    const browser: ICefBrowser; const frame: ICefFrame; 
    const request: ICefRequest; navType: TCefHandlerNavtype; isRedirect: Boolean; 
    out Result: Boolean); 
begin 
    if request.Url = PopupURL then 
    begin 
    Result := True; 
    ShellExecute(Handle, 'open', PChar(request.Url), '', '', SW_SHOWNORMAL); 
    end; 
end; 

procedure TForm1.Chromium1BeforePopup(Sender: TObject; 
    const parentBrowser: ICefBrowser; var popupFeatures: TCefPopupFeatures; 
    var windowInfo: TCefWindowInfo; var url: ustring; var client: ICefBase; 
    out Result: Boolean); 
begin 
{ 
    // Solution 1 
    // this will block the popup window creation and cancel the navigation to 
    // the target, so we have to perform the ShellExecute action here as well 
    if url = PopupURL then 
    begin 
    Result := True; 
    ShellExecute(Handle, 'open', PChar(url), '', '', SW_SHOWNORMAL); 
    end; 
} 
{ 
    // Solution 2 
    // or we can set the m_bWindowRenderingDisabled flag to True and the window 
    // won't be created (as described in ceflib.pas), but the navigation continue 
    if url = PopupURL then 
    windowInfo.m_bWindowRenderingDisabled := True; 
} 
end; 
+4

ग्रेट उत्तर, धन्यवाद। –

संबंधित मुद्दे

 संबंधित मुद्दे