#---8<---new-IENamed.ps1---Jean-JMST-Belgium--- #=4/2007==================================Version 0=====# #== Creates or gets an Internet Explorer named window ==# # # PARMETERS # $name : name of the window to create or to get # $code (string containing JScript code): # If not present a new window named $name is created. # An InternetExplorer.Application object is returned. # If present get the IE window named $name and executes # JScript code. # Result of JScript code is returned. # # EXAMPLES # # Create an new IE window named CHARLIE, write CHAPLIN # in it's document and close after 15 seconds: # $ie=.\New-IENamed 'CHARLIE' # $ie.visible=$true # $ie.document.body.innerText='CHAPLIN' # Start-Sleep 15 # $ie.Quit() # # Get an IE window named CHARLIE and : # -output the screenLeft property # .\New-IENamed 'CHARLIE' 'screenLeft' # # -retrieve the document object, write CHAPLIN # ,change body background color, set an # onclick event on the body and close after # 10 seconds # $iedoc=.\New-IENamed 'CHARLIE' 'document' # $iedoc.IHTMLDocument2_write('CHAPLIN') # $iedoc.body.style.backgroundColor='tomato' # .\New-IENamed 'CHARLIE' 'document.body.onclick= # function(){alert("CHAPLIN")}' # Start-Sleep 10 # .\New-IENamed 'CHARLIE' 'close()' # # -show a dialog box saying CHAPLIN # .\New-IENamed 'CHARLIE' 'alert("CHAPLIN")' # #=========Tested on PowerShell 1========================# param([string]$name,[string]$code) if(!$name){return $false} $SC=New-Object -com ScriptControl $SC.Language='JScript' $JScode= 'function IE_Named(iename,code){'+ ' with(ie=new ActiveXObject("InternetExplorer.Application")){'+ ' navigate("about:blank");'+ ' while(busy){void true};'+ ' with(document.parentWindow){'+ ' if(code){'+ ' with(open("",iename)){'+ ' var r=eval(code)'+ ' };'+ ' quit();'+ ' return r'+ ' }'+ ' else{'+ ' name=iename;'+ ' return ie'+ ' }'+ ' }'+ ' }'+ '}' $SC.AddCode($JScode) $script=$SC.CodeObject if($code){ return $script.IE_Named($name,$code) } else{ return $script.IE_Named($name,$false) } #---8<---new-IENamed.ps1---Jean-JMST-Belgium---