【问题标题】:No session share and avoid navigation buttons in browser while opening application window打开应用程序窗口时无会话共享并避免浏览器中的导航按钮
【发布时间】:2011-09-29 17:38:08
【问题描述】:

我们正在使用 VBScript 代码打开应用程序窗口,以避免用户在打开 IE8 窗口时进行前进/后退导航。

这是使用的代码。

Set WshShell = CreateObject("shell.application")
Set IE=CreateObject("InternetExplorer.Application")
IE.menubar = 1
IE.toolbar = 0
IE.statusbar = 0
'here we open the application url
IE.navigate "http://www.google.com" 
IE.visible = 1
WshShell.AppActivate(IE)

这工作正常,但问题是如果用户打开多个窗口,会话 cookie 会跨窗口共享。

为此还有一个解决方案,我们可以在打开 IE 时使用 nomerge 选项

WshShell.ShellExecute "iexplore.exe", " -nomerge http://www.google.com", null, null, 1

现在我们希望这两个选项都可用。即用户不应该能够向前/向后导航,并且如果打开了两个窗口,则不应共享数据。

我们无法让这两件事一起工作。

我们也不想要任何全屏模式(即按 F11 后)

谁能提供解决方案?

提前致谢。

【问题讨论】:

    标签: asp.net internet-explorer-8 vbscript


    【解决方案1】:

    查看这个非常相关的问题的答案:Launch Internet Explorer 7 in a new process without toolbars。有几个可行的选项,一个使用 Powershell,一个使用一些笨拙的 VBScript。

    【讨论】:

    • 你的回答给了我答案的方向。
    【解决方案2】:

    据我了解,cookie 是按实例设置的。多个浏览器窗口仍将是同一个实例。

    您也许可以传入程序跟踪的某种 ID 参数,但浏览器不能。这样,无论程序如何运行,它都会有自己的“会话”ID。

    我认为您可以使用 javascript 执行此操作,并使用 asp.net 隐藏字段读取它。这可能会给您带来您正在寻找的独特性。

    <asp:HiddenField ID="HiddenFieldSessionID" runat="server" />
    
    protected void Page_Load(object sender, EventArgs e)
    {
        HiddenFieldSessionID.Value = Session.SessionID;
    }
    
    
    <script type="text/javascript">
        function ShowSessionID()
        {
            var Hidden;
            Hidden = document.getElementById("HiddenFieldSessionID");
    
            document.write(Hidden.value);
        }
    </script>
    

    【讨论】:

    • 我们正在尝试从 vbscript 打开应用程序。即用户将点击vbscript文件打开应用程序,用户无法直接打开浏览器。
    • 不管它将如何打开,我的帖子的重点是您可以使用 VBScript 以编程方式执行此操作,为将要打开的每个“窗口”设置一个会话变量。然后,您可以通过浏览器 cookie 以外的程序中的会话变量来跟踪数据。我只是给出了一个使用 javascript 的简短示例,因为我的 VBScript 知识非常糟糕。
    【解决方案3】:

    patmortech 回答的链接中提到的解决方案并不完美,因为 cookie 仍然共享。所以在 AppToRun 变量中使用了 -nomerge 选项,当用户在一台机器上打开应用程序两次时,它会创建两个进程。

    在 IE8 中,如果打开了两个 Internet Explorer,则它们会合并到一个进程中,因此 -nomerge 选项会在不同进程中打开 IE8 实例。

     On Error Resume Next
    
    AppURL = "http://www.stackoverflow.com"
    AppToRun = "iexplore -nomerge"
    AboutBlankTitle = "Blank Page"
    LoadingMessage = "Loading stackoverflow..."
    ErrorMessage = "An error occurred while loading stackoverflow.  Please close the Internet Explorer with Blank Page and try again.  If the problem continues please contact IT."
    EmptyTitle = ""
    
    'Launch Internet Explorer in a separate process as a minimized window so we don't see the toolbars disappearing
    dim WshShell
    set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run AppToRun, 6
    
    dim objShell
    dim objShellWindows
    
    set objShell = CreateObject("Shell.Application")
    set objShellWindows = objShell.Windows
    
    dim ieStarted
    ieStarted = false
    
    dim ieError
    ieError = false
    
    dim seconds
    seconds = 0
    
    while (not ieStarted) and (not ieError) and (seconds < 30)
    
        if (not objShellWindows is nothing) then
            dim objIE
            dim IE
    
            'For each IE object
            for each objIE in objShellWindows
    
                if (not objIE is nothing) then
    
                    if isObject(objIE.Document) then
                        set IE = objIE.Document
    
                        'For each IE object that isn't an activex control
                        if VarType(IE) = 8 then
    
                            if IE.title = EmptyTitle then
                                if Err.Number = 0 then
                                    IE.Write LoadingMessage
    
                                    objIE.ToolBar = 0
                                    objIE.StatusBar = 1
                                    objIE.Navigate2 AppURL
    
                                    ieStarted = true
                                else
                                    'To see the full error comment out On Error Resume Next on line 1
                                    MsgBox ErrorMessage
                                    Err.Clear
    
                                    ieError = true
    
                                    Exit For
                                end if
                            end if
                        end if
                    end if
                end if
    
                set IE = nothing
                set objIE = nothing
            Next
        end if
    
        WScript.sleep 1000
        seconds = seconds + 1
    wend
    
    set objShellWindows = nothing
    set objShell = nothing
    
    'Activate the IE window and restore it
    success = WshShell.AppActivate(AboutBlankTitle)
    
    if success then 
        WshShell.sendkeys "% r"  'restore 
    end if
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-18
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 2015-04-22
      • 2011-05-24
      • 1970-01-01
      相关资源
      最近更新 更多