2011-09-23 18 views
1

我们使用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将在Windows中共享。

对于这个也有,同时打开IE

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

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

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

此外,我们不希望(按F11之后即)

任何全屏模式,任何一个可以提供解决方案?

在此先感谢。

回答

0

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

在IE8中,如果打开两个互联网浏览器,那么它们将合并到单个进程中,因此-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 
0

据我所知,饼干是由实例设置的。多个浏览器窗口仍然是同一个实例。

您可能可以传入程序跟踪的某种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> 
+0

我们正试图从vbscript打开应用程序。即用户将点击vbscript文件打开应用程序,用户不能直接打开浏览器。 – dhinesh

+0

无论打开如何打开,我的文章的要点是,你可以使用VBScript以编程方式进行操作,为每个将打开的“窗口”设置一个会话变量。然后,您可以通过浏览器cookie以外的程序中的会话变量跟踪数据。 我刚刚给了一个简短的例子使用JavaScript,因为我的VBScript知识是非常糟糕的。 – Gobbledigook

相关问题