Jump to content


Photo

Navigate to javascript


  • Please log in to reply
5 replies to this topic

#1 neva31

neva31
  • Members
  • 51 posts

Posted 28 May 2011 - 07:06 PM

Hi,
The 1st block of code works but the second doesn't and gives an error message saying "Internet Explorer cannot download".
Does anyone know how to get the second block of code to work, i.e. is there a way to navigate straight to javascript from a new instance of ie, rather than having to use an existing instance.
Thanks.

IEGet(Name="")      ;Retrieve pointer to existing IE window/tab 
{ 
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame 
      Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs" 
      : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" ) 
   For Pwb in ComObjCreate( "Shell.Application" ).Windows 
      If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" ) 
         Return Pwb 
} ;written by Jethrow

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("www.google.co.uk")
While ie.readystate <> 4 
sleep 50
Pwb := IEGet()   ;Tab name you define can also be a variable
Pwb.Navigate("javascript:newWin=window.open('http://www.autohotkey.com', 'newwin', 'width=500, height=500, toolbar=0, resizable=0, location=0, menubar=0, scrollbars=0'); newWin.focus();")

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("javascript:newWin=window.open('http://www.autohotkey.com', 'newwin', 'width=500, height=500, toolbar=0, resizable=0, location=0, menubar=0, scrollbars=0'); newWin.focus();")
While ie.readystate <> 4 
sleep 50


#2 jethrow

jethrow
  • Fellows
  • 2549 posts

Posted 28 May 2011 - 09:36 PM

How about accessing the window object via AHK rather than javascript:
IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWINDOW2

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("www.google.com")

window := ComObj(9, ComObjQuery(ie,IID,IID), 1)
; window := ie.document.parentWindow

newWin := window.open("http://www.autohotkey.com")
while, % newWin.document.readystate != "complete"
	sleep, 10
MsgBox, % newWin.document.title
NOTE - I used ComObjQuery to access the window to bypass security warnings

#3 neva31

neva31
  • Members
  • 51 posts

Posted 28 May 2011 - 10:50 PM

Thanks, but I am using the javascript to get a standardised IE window without a toolbar and I don't know how to do that in COM.
I also tried embedding the browser in a GUI to get a standardised window but unfortunately the GUI browser won't work with my company's CMS, which is what I want to use it with.

#4 tank

tank
  • Members
  • 4105 posts

Posted 29 May 2011 - 05:38 AM

;~ New internet explorer window always on top with titlebar only
	iWeb_Model(h=550,w=900)
	{
		;"False" ;"True" ;uncomment to show
	;~ 	COM_Invoke(pwb,"ToolBar",1)
		If	pwb := (pwb := iWeb_newIe()) ? (pwb,	COM_Invoke(pwb,"MenuBar",0),	COM_Invoke(pwb,"AddressBar",0),	COM_Invoke(pwb,"StatusBar",0),	COM_Invoke(pwb,"Height",h),	COM_Invoke(pwb,"Width",w)) : 
		WinSet,AlwaysOnTop,On,% "ahk_class " COM_Invoke(pwb,"hwnd")
		Return	pwb
	}


COM_Invoke(pwb,"MenuBar",0)
	COM_Invoke(pwb,"AddressBar",0)
	COM_Invoke(pwb,"StatusBar",0)
	COM_Invoke(pwb,"Height",h)
	COM_Invoke(pwb,"Width",w)

	pwb.MenuBar := 0
	pwb.AddressBar := 0
	pwb.StatusBar := 0
	pwb.Height := 500
	pwb.Width := 400

etceteraetcetera

#5 neva31

neva31
  • Members
  • 51 posts

Posted 29 May 2011 - 04:20 PM

Great, thanks. I'm almost there, I used the code to create the script below. However I've screwed it up slightly, it opens a new IE window with no address, status or toolbar but it doesn't navigate to any web page, just stays as a grey window. Can anyone point out where I've gone wrong.
Thanks
;~ A new internet explorer window
	iWeb_newIe()
	{
		Return	pweb := (pweb := ComObjCreate("InternetExplorer.Application") ) ? (pweb,pweb.visible := True) : 0
	}
	
;~ New internet explorer window always on top with titlebar only
   iWeb_Model(w,h)
   {
      ;"False" ;"True" ;uncomment to show
   ;~    COM_Invoke(pwb,"ToolBar",1)
      If pwb := (pwb := iWeb_newIe()) ? (pwb,pwb.MenuBar:= 0,pwb.AddressBar:= 0,pwb.StatusBar:= 0,pwb.ToolBar:= 0,pwb.Height:= h,pwb.Width:= w) : 
      WinSet,AlwaysOnTop,On,% "ahk_class " pwb.hwnd
      Return   pwb
   }
  
iWeb_Model(1024, 600)
pwb.Visible := true
pwb.Navigate("http://www.google.co.uk")
While pwb.readystate <> 4 
Sleep, 50


#6 neva31

neva31
  • Members
  • 51 posts

Posted 29 May 2011 - 09:22 PM

This seems to work for what i wanted. Thanks all for your help.

Nav(URL)
{
pwb := ComObjCreate("InternetExplorer.Application")
pwb.menuBar:=0,pwb.AddressBar:=0,pwb.StatusBar:=0,pwb.ToolBar:=0,pwb.height:="600",pwb.width:="1024"  
pwb.Visible := true
pwb.Navigate(URL)
While pwb.readystate <> 4 
sleep 50
}

Nav("www.google.co.uk")