News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

web page link not in new page but in the same page

Started by TouEnMasm, August 27, 2014, 02:04:55 AM

Previous topic - Next topic

TouEnMasm

Some links ,in web pages,ask to create a new page and some others need to stay in the same page.
I search a way to use allways the same page.
One idea ?
 
Fa is a musical note to play with CL

Tedd

This all depends how the browser treats new links. The default is to open links in the same page, but any link can be given a 'target' attribute which names a new page, and so the browser will create a new page in which to open that link.
So, if you can remove target attributes from links, you'll get all links opening in the same page. Alternatively, if you have additional control over the browser, you may be able to force it to always open links in the same page.
Potato2

dedndave

<a href="http://www.masm32.com">Masm32</a>
<a href="http://www.masm32.com" target="_blank">Masm32</a>


the first html "a" tag will link in the same window
this is, of course, provided the browser is set up to do so, as Tedd mentioned
this is normally the default browser setting

the second one will open the link in a new window

_self, _parent, or _top are other valid target keywords

TouEnMasm


I was thinking about some events during the navigation.
Looking in the sample Internet Browser of Japheth,I found a file named eventobj.asm.
He implement the DWebBrowserEvents Interface
Hopefully,there is a comment in the source code who say:
Quote
   .elseif ( eax == DISPID_NEWWINDOW3 )

      DebugOut "CEvent@DWebBrowserEvents2::NewWindow3()"
      ;--- this event is used since IE 6.
      ;--- cancel "new window" navigation
      invoke GetParam, addr vt, esi, 1, [ebx].DISPPARAMS.cArgs
      mov ecx, vt.byref
      mov VARIANT_BOOL ptr [ecx], VARIANT_TRUE

      mov ecx, pThis
      invoke IsZoomed, [ecx].CEvent.m_hwndFrame
      mov edx, SW_SHOWMAXIMIZED
      .if ( eax == 0 )
         mov edx, SW_SHOWNORMAL
      .endif
      push edx
      ;--- get the new URL
      invoke GetParam, addr vt, esi, 4, [ebx].DISPPARAMS.cArgs
      pop edx
      invoke NewWindow, vt.bstrVal, COF_VISIBLE, edx
      invoke VariantClear, addr vt

Perhaps the soluce

Fa is a musical note to play with CL

TouEnMasm


Found the Soluce given by MSDN ,The Idispatch member of the event must be change by the Iwebbrowser created by the source code.
There is too  many precautions in the source code,but it is a testing piece to show the use of the dispid parameters.
Avoid an headache with DispGetParam,read this.


DWebBrowserEvents2_Invoke PROC uses edi esi ebx _this:DWORD, dispIdMember, riid, lcid, wFlags, pdispparams, pVarResult, pExcepInfo, puArgErr
local varg0:VARIANT,varResultDummy:VARIANT,uArgErr:DWORD,retour:DWORD,ppvIUnknown
IF Espion EQ 2
invoke EcrireRapport,TXT("DWebBrowserEvents2_Invoke",13,10)
ENDIF
;DISPPARAMS STRUCT DEFALIGNMASM
; rgvarg DWORD ? ;VARIANT *
; rgdispidNamedArgs DWORD ? DISPID *
; cArgs DWORD ?
; cNamedArgs DWORD ?
;DISPPARAMS ENDS
;DispGetParam
;DISPID_PROPERTYCHANGE
;DISPID_PROPERTYCHANGE
;DISPID_FILEDOWNLOAD
;DISPID_NAVIGATECOMPLETE2

mov eax, dispIdMember

.if  eax == DISPID_NEWWINDOW3
;http://msdn.microsoft.com/en-us/library/aa768288(v=vs.85).aspx
mov ebx, pdispparams ;pointer on an array of DISPPARAMS structure with [n]
;-------------------- DispGetParam  -----------------------------------------------
;[0] ppDisp Idispatch browser
;[1] Cancel A Boolean value that determines whether the current navigation should be canceled
;[2] dwFlags [in]Type: Long The flags from the NWMF enumeration that pertain to the new window
;[3] bstrUrlContext [in] Type: BSTR The URL of the page that is opening the new window
;[4] bstrUrl [in] Type: BSTR The URL that is opened in the new window.
;-----------------------------------------------------------------------------------------
;-------------------- mov ebx,pdispparams [x * sizeof DISPPARAMS] -----------------------------------------------
;[4] ppDisp Idispatch browser
;[3] Cancel A Boolean value that determines whether the current navigation should be canceled
;[2] dwFlags [in]Type: Long The flags from the NWMF enumeration that pertain to the new window
;[1] bstrUrlContext [in] Type: BSTR The URL of the page that is opening the new window
;[0] bstrUrl [in] Type: BSTR The URL that is opened in the new window.
;-----------------------------------------------------------------------------------------
;   // It simplifies the following code if the caller
    ;// ignores the return value.
    .if puArgErr == NULL
      lea edx,uArgErr
mov puArgErr,edx
.endif
    .if pVarResult == NULL
      lea edx,varResultDummy
mov pVarResult,edx
.endif
invoke VariantInit,addr varg0
  ; // Assume the return type is void, unless otherwise is found.
    invoke VariantInit,pVarResult
;--------------------------- ---------------------------------------
;----------------- cancel Navigation ,don't show the page ----------
;--------------------------------------------------------------------
invoke DispGetParam,pdispparams,1,VT_BOOL,addr varg0,puArgErr
;made a test,is it what we want ?
.if eax == S_OK
mov ecx, pdispparams
mov   edx,[ecx].DISPPARAMS.rgvarg ;pointeur sur variant
add   edx,3*sizeof VARIANT
;mov edx, [ecx+3*sizeof VARIANT]
mov ecx, [edx].VARIANT.n1.n2.n3.pvarVal ;adresse de la valeur
;-------------------------------------
;cancel = TRUE
;-------------------------------------
;mov word ptr [ecx],TRUE ;ça marche
.endif
invoke VariantInit,addr varg0
  ; // Assume the return type is void, unless otherwise is found.
    invoke VariantInit,pVarResult
;---------------------------------------------------------------------------------
;------------ Change Idispatch (IWebBrowser2) to keep the same page -------------
;---------------------------------------------------------------------------------
invoke DispGetParam,pdispparams,0,VT_DISPATCH,addr varg0,puArgErr
;made a test,is it what we want ?
.if eax == S_OK
mov ecx, pdispparams
mov   edx,[ecx].DISPPARAMS.rgvarg ;pointeur sur variant
add edx, 4 *sizeof VARIANT
movzx eax,[edx].VARIANT.n1.n2.vt
.if eax == VT_DISPATCH
mov ecx, [edx].VARIANT.n1.n2.n3.pdispVal ;adresse de la valeur
mov eax,ppvIWebBrowser2
mov [edx].VARIANT.n1.n2.n3.pdispVal,eax
mov edx,varg0.n1.n2.n3.pdispVal
.endif
.endif

;MSDN
;vt Value Corresponding value member name
;VT_I4 lVal
;VT_DISPATCH pdispVal
;VT_BSTR bstrVal
;VT_EMPTY none


FindeDWebBrowserEvents2_Invoke:
mov eax,S_OK
ret
Fa is a musical note to play with CL

TouEnMasm


Final soluce:
put cancel = true
get the url for the window
recall IWebBrowser2 Navigate2,addr myURL, 0, 0, 0, 0
And there is no new page created

invoke ReadDispVariant,0,pdispparams ;url pour new window
mov Durl,eax
invoke WideCharToMultiByte,CP_ACP,NULL,Durl,\
-1,addr url,LENGTHOF url,NULL,NULL

;cancel = TRUE
invoke WriteDispVariant,3,pdispparams,0,0,TRUE
invoke DisplayHTMLPage,fenetre.Hwnd,addr url

return S_OK

Fa is a musical note to play with CL