Today, using CDHtmlDialog to create a simple browser program, encountered a problem, a record.
Problem Description: When the hyperlink is opened in _blank, a server busy dialog box pops up,
Web content
Click on the Baidu Link, the following dialog box appears:
If the page code in the open mode of a tag is not _blank can be normal page jump, the page code changed to the following way, normal jump:
Post-jump page:
Baidu in the news bar and other links open way is also in _blank way, if you click a link, will appear above the Service Busy dialog box, the following gives click Paste:
I do not know why, is not enough pages to open a new page, I hope to know the master can tell why.
Solution:
Since it is caused by the opening of the A-label, let's deal with the A-tag.
Idea: 1, get the label of the click Position
2. Get the tag name to see if it is a label
3, if it is a tag, get open mode, and get href URL
4. Close the current page and open the page where the href is pointing
In PreTranslateMessage to get the mouse down message, in the mouse down message processing whether a tag, and open mode for _blank a label processing, the following gives the page to determine the location of the tag code:
BOOL Cantinettimeoutdlg::isatag () {CComVariant variant (NULL); CString Strtarget,strtagname,strhref; BSTR Sztagname;long NTop; CPoint point;ihtmlelement *pelement = null;::atl::ccomptr<ihtmldocument2> Sphtmldoc; Lpdispatch lpdisp = NULL; GetCursorPos (&point); ScreenToClient (&point); m_pbrowserapp->get_document (&LPDISP); HRESULT hr = Lpdisp->queryinterface (Iid_ihtmldocument2, (void**) &sphtmldoc); if (Sphtmldoc) {if (SPHTMLDOC.P) {m_pbrowserapp->get_top (&ntop);//Gets the page form distance from the top of the dialog box if (sphtmldoc.p-> elementFromPoint (point.x,point.y-ntop,&pelement) = = S_OK)//corrects the value on the Y-direction of the mouse click and needs to subtract the height value from the top of the form {if (pelement! = NULL) { hr = Pelement->get_tagname (&sztagname);//Gets the label name if (sztagname! = NULL) {Strtagname.format (_t ("%s"), sztagname); if (Strtagname.comparenocase (_t ("a")) = = 0)//judgment is non-a tag {hr = Pelement->getattribute (_t ("target"), 0,&variant);// Get Open With if (VARIANT.VT = = vt_bstr) {strtarget = Variant.bstrval;if (Strtarget.comparenocase (_t ("_blank")) = = 0)//judging non _ Blank{peLement->getattribute (_t ("href"), 0,&variant);//Get the connection address if (VARIANT.VT = = vt_bstr) {strhref = Variant.bstrval;if ( Pathisurl (Strhref)) {sphtmldoc->clear (); Sphtmldoc->close ();//Close the current page, open the page where the href is pointing navigate (Strhref);}} return TRUE;}}} }}}}}return FALSE;}
In this way, the above problems are temporarily resolved (because they do not know the real reason for the above problems).
CDHtmlDialog browser is experiencing server busy (server Busy) issues