2011-09-23 22 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

相關問題