locked
Save and close message RRS feed

  • Question

  • Hi everybody,

    I'm developing an iframe which is basically a grid view of accounts.

    When a user double click on a company name, a primary contact or any similar information, the CRM window of the correspondant record is opened. My problem is when I change informations in this window and click "Save and close" I get a pop up message "The webpage you are viewing is trying to close this window. Do you want to close the window?".

    This is very annoying for my client who want it removed.

    Here is an example of how I open the CRM window.

                Dim URL As String = "http://WIN-64QI7GB3GK2/TF/sfa/conts/edit.aspx?id={" & Row.PrimaryContactId.ToString & "}#"
                Process.Start("iexplore.exe", URL)

    I tried to look on the web, it's likely someone already have solved this but I didn't find any specific solution so far. That's why I'm asking for your help.

    I can provide more informations, thank you in advance ;D.




    • Edited by Enro67 Tuesday, August 13, 2013 8:46 AM
    Tuesday, August 13, 2013 7:58 AM

Answers

  • Hi,

    The problem is that the Javascript context of the window doesn't have permissions to close the browser window because the window was created by your Proess.Start and not by the dynamics crm domain.

    What technology are you writing your iframe in? Is it a smart client app, silverlight?

    You could try using the default browser behaviour (use Process.Start(URL)) - or you could embed IE in a host window so that you can control when it closing and the messages it gives.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, August 13, 2013 8:45 AM
    Answerer
  • Ok, I have my answer. I will use a host window. Thank you very much for your help, thanks to you I know in which direction go :).

    EDIT : I finally had the time to resolve this problem. I give a short sample of what can be done for those who have the same issue as me.

    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Runtime.InteropServices
    Imports SHDocVw
    Imports System.ComponentModel
    
    Public Class InternetExplorer
    
        Private Shared _instance As InternetExplorer = Nothing
        Private WithEvents _IEBrowser As SHDocVw.InternetExplorer
    
        <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
        End Function
    
        'Singleton, optional but in my case I don't want the user to open multiple instance of this class
        Public Shared Function GetInstance() As InternetExplorer
            If IsNothing(_instance) Then
                _instance = New InternetExplorer
            End If
            Return _instance
        End Function
    
        'Occurs after saving the changes but before the message pop up
        Private Sub WindowClosingEvent() Handles _IEBrowser.WindowClosing
            Try
                KillWindow()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
            End Try
        End Sub
    
        'Open the specified URL
        Public Sub OpenURL(URL As String)
            If _IEBrowser Is Nothing Then
                _IEBrowser = New SHDocVw.InternetExplorer
            End If
    
            _IEBrowser.Visible = True
            _IEBrowser.Navigate2(URL, String.Empty, String.Empty, String.Empty, String.Empty)
        End Sub
    
        'Send the WM_CLOSE message to the window using his handle
        Private Sub KillWindow()
            Dim returnValue As IntPtr
            Dim WM_CLOSE As IntPtr = &H10
    
            returnValue = SendMessage(CType(_IEBrowser.HWND, IntPtr), WM_CLOSE, 0, 0)
            _IEBrowser = Nothing
    
            If Not returnValue = 0 Then
                'An error occured
                Throw New Win32Exception(Marshal.GetLastWin32Error())
            End If
        End Sub
    
    End Class
    


    • Edited by Enro67 Friday, August 23, 2013 10:17 AM
    • Marked as answer by Enro67 Friday, August 23, 2013 12:13 PM
    Tuesday, August 13, 2013 9:39 AM

All replies

  • Hi,

    The problem is that the Javascript context of the window doesn't have permissions to close the browser window because the window was created by your Proess.Start and not by the dynamics crm domain.

    What technology are you writing your iframe in? Is it a smart client app, silverlight?

    You could try using the default browser behaviour (use Process.Start(URL)) - or you could embed IE in a host window so that you can control when it closing and the messages it gives.

    hth


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, August 13, 2013 8:45 AM
    Answerer
  • Thank you for your answer,

    The iframe is written in VB (ASP.NET) and the interfaces are made in XAML (WPF), yes it's a smart client app.

    I already tried Process.Start(URL) without any difference in my case. I would prefer to not use a host window. Actually, since it's a permission problem, I hoped there would be some way to pass/force parameters on the web page in order to have the same behavior that if the window was created by the CRM domain. 


    • Edited by Enro67 Tuesday, August 13, 2013 9:21 AM
    Tuesday, August 13, 2013 9:20 AM
  • You can't do it on the server since it's a Client sandbox restriction. There is no setting I know of that can turn this warning off.


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, August 13, 2013 9:26 AM
    Answerer
  • Ok, I have my answer. I will use a host window. Thank you very much for your help, thanks to you I know in which direction go :).

    EDIT : I finally had the time to resolve this problem. I give a short sample of what can be done for those who have the same issue as me.

    Imports System
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Runtime.InteropServices
    Imports SHDocVw
    Imports System.ComponentModel
    
    Public Class InternetExplorer
    
        Private Shared _instance As InternetExplorer = Nothing
        Private WithEvents _IEBrowser As SHDocVw.InternetExplorer
    
        <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
        Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
        End Function
    
        'Singleton, optional but in my case I don't want the user to open multiple instance of this class
        Public Shared Function GetInstance() As InternetExplorer
            If IsNothing(_instance) Then
                _instance = New InternetExplorer
            End If
            Return _instance
        End Function
    
        'Occurs after saving the changes but before the message pop up
        Private Sub WindowClosingEvent() Handles _IEBrowser.WindowClosing
            Try
                KillWindow()
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
            End Try
        End Sub
    
        'Open the specified URL
        Public Sub OpenURL(URL As String)
            If _IEBrowser Is Nothing Then
                _IEBrowser = New SHDocVw.InternetExplorer
            End If
    
            _IEBrowser.Visible = True
            _IEBrowser.Navigate2(URL, String.Empty, String.Empty, String.Empty, String.Empty)
        End Sub
    
        'Send the WM_CLOSE message to the window using his handle
        Private Sub KillWindow()
            Dim returnValue As IntPtr
            Dim WM_CLOSE As IntPtr = &H10
    
            returnValue = SendMessage(CType(_IEBrowser.HWND, IntPtr), WM_CLOSE, 0, 0)
            _IEBrowser = Nothing
    
            If Not returnValue = 0 Then
                'An error occured
                Throw New Win32Exception(Marshal.GetLastWin32Error())
            End If
        End Sub
    
    End Class
    


    • Edited by Enro67 Friday, August 23, 2013 10:17 AM
    • Marked as answer by Enro67 Friday, August 23, 2013 12:13 PM
    Tuesday, August 13, 2013 9:39 AM
  • Thanks for posting the update - very helpful.

    Cheers,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Friday, August 23, 2013 12:15 PM
    Answerer