Home > Article > Web Front-end > Read the onclick attribute value of the page element, prohibit redirection, and obtain the redirection target specified by the Location header after url redirection_html/css_WEB-ITnose
(1) Read the onclick attribute value of the page element
html code:
Get the value of the onclick attribute on the item: alert('ok');
Implementation:
IHTMLElement *item;// 已经找到该元素CComQIPtr<IHTMLElement> spElem(item);VARIANT var;spElem->get_onclick(&var);CComQIPtr<IDispatch> spDisp(var.pdispVal);DISPID dispId = 0;OLECHAR *szName = L"toString";spDisp->GetIDsOfNames(IID_NULL, &szName, 1, LOCALE_SYSTEM_DEFAULT, &dispId);DISPPARAMS params;memset(¶ms, 0, sizeof(params));VARIANT varRet;spDisp->Invoke(dispId, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, ¶ms, &varRet, NULL, NULL);CString k= CString(varRet.bstrVal);
Disable redirection with INTERNET_FLAG_NO_AUTO_REDIRECT
DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII|INTERNET_FLAG_NO_AUTO_REDIRECT;
cFile = (CHttpFile*)Sess.OpenURL(url,1,dwFlags);
Get the redirection target specified by the Location header after url redirection
cFile ->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, cstrLocation);