crzymnmchl

get _IECreateEmbedded to work with html page loading js library

1 post in this topic

I cannot get any of my localhost pages that use Angular, jQuery, ExtJS etc to load into the embedded. All work perfectly with _IECreate of course. I started with

$oNav = _IENavigate($oIE, @ScriptDir & '/angularjs-hello-world.html', 0)

but that gave me nothing but _IE error messages with long integers - so went simpler(?) to my local server with

$oNav = _IENavigate($oIE, 'http://localhost:8080/Angular/angularjs-hello-world.html')

which opens the embedded page

<!-- saved from url=(0016)http://127.0.0.1 -->
<!DOCTYPE html>
<html>

<head>
    <script src="js/libs/angular.min.js"></script>
</head>

<body ng-app>
  <input type="text"
         ng-model="name"
         placeholder="Enter your name">
  <h1>Hello <span ng-bind="name"></span></h1>

</body>

</html>

but with no Angular ... the html objects are there e.g the input field but the Angular "Enter your name" is not there .... I do not think the js library is loading.

#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>

Local $oIE = _IECreateEmbedded()
GUICreate("Embedded Web control Test", 640, 580, _
        (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _
        $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUICtrlCreateObj($oIE, 10, 40, 600, 360)

Global $g_idError_Message = GUICtrlCreateLabel("", 100, 500, 500, 30)
GUICtrlSetColor(-1, 0xff0000)

GUISetState(@SW_SHOW) ;Show GUI

_IENavigate($oIE, 'http://localhost:8080/Angular/angularjs-hello-world.html')
CheckError("Init", @error, @extended)

; Waiting for user to close the window
While 1
    Local $iMsg = GUIGetMsg()
    Select
        Case $iMsg = $GUI_EVENT_CLOSE
            ExitLoop        
    EndSelect
WEnd

GUIDelete()

Exit

Func CheckError($sMsg, $iError, $iExtended)
    If $iError Then
        $sMsg = "Error using " & $sMsg & " button (" & $iExtended & ")"
    Else
        $sMsg = ""
    EndIf
    GUICtrlSetData($g_idError_Message, $sMsg)
EndFunc   ;==>CheckError

Works perfectly when run from localhost: and also when the html file is run from file system. The example for _IECreateEmbedded (which I shortened above) goes to www.autoit which loads jQuery so I know doable. First comment in html is meant to tweek IE security and I have been giving IE as much activeX settings as possible as I wonder if this is Win7/IE11 security?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • milos83
      By milos83
      I have one script that creates _IECreateEmbedded and another script that does _IEAttach.
      I do this because when autoit is doing something, the Embedded IE starts stalling (eg jquery progress animation)
      But there is a new problem.
      When IE is having its own process (like in the example above) any _IE command is slow (in the script that Attaches).
      Here is a comparison of when its in separate and when its in same process:
      Separate process _IETagNameGetCollection : 5000ms
      Separate process _IEAction: 850ms
      Same process _IETagNameGetCollection : 1ms
      Same proccess _IEAction: 135ms
       
      If I try to attach to an embedded IE that is done in c#, I get lightning fast results.
      As you can see, _IE functions work very slow when the embedded IE we are attaching to is made in Autoit.
       
      I did a test and if I empty the WHILE loop in IE process I get these results(but the cpu is at 30% as expected):
      Separate process _IETagNameGetCollection : 33ms
      Separate process _IEAction: 13ms
       
      It slows down if you put anything (like GUIGetMsg) in the WHILE loop.
       
      How do I fix this?
       
      Create IE:
      #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> Local $oIE = _IECreateEmbedded() GUICreate("My Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE, 10, 40, 600, 360) GUISetState(@SW_SHOW) ;Show GUI _IENavigate($oIE, "http://www.autoitscript.com") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ;takes 1ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ;takes 135ms ConsoleWrite(TimerDiff($timer) & @CRLF) While 1 Local $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd  
      Attach to IE:
      #include <IE.au3> Local $oIE = _IEAttach("My Embedded Web control Test", "embedded") $timer = TimerInit() $oLink = _IETagNameGetCollection($oIE, "a", 3) ; 5000ms ConsoleWrite(TimerDiff($timer) & @CRLF) $timer = TimerInit() _IEAction($oLink, "click") ; 850ms ConsoleWrite(TimerDiff($timer) & @CRLF)  
       
      attach.au3
      create.au3
    • Chimp
      By Chimp
      An example on how to inject jQuery into a web page
      It can be useful to manage the page from AutoIt using jQuery.
      Idea from here: http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
      Suggestions and improvements are welcome
      #include <ie.au3> Example() Func Example() Local $oIE = _IECreate("www.google.com") Local $jQuery = _jQuerify($oIE) MsgBox(0, "Version", "jQuery version: " & $jQuery.fn.jquery) MsgBox(0, "Example", "click ok to exit." & @CRLF & "Google logo will fade out by jQuery...") $jQuery('#hplogo').fadeOut(3000) ; jQuery will fade out the google logo EndFunc ;==>Example ; #FUNCTION# ==================================================================================================================== ; Name ..........: _jQuerify ; Description ...: ; Syntax ........: _jQuerify(Byref $oIE) ; Parameters ....: $oIE - Object variable of an InternetExplorer.Application. ; Return values .: an object variable pointing to the jQuery library ; Author ........: Chimp ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: ; =============================================================================================================================== Func _jQuerify(ByRef $oIE) Local $jsEval, $jQuery, $otherlib = False ; create a reference to the javascript eval() function $oIE.document.parentWindow.setTimeout('document.head.eval = eval', 0) Do Sleep(250) $jsEval = Execute('$oIE.Document.head.eval') Until IsObj($jsEval) ; if jQuery is not already loaded then load it If $jsEval("typeof jQuery=='undefined'") Then ; check if the '$' (dollar) name is already in use by other library If $jsEval("typeof $=='function'") Then $otherlib = True Local $oScript = $oIE.document.createElement('script'); $oScript.type = 'text/javascript' ; If you want to load jQuery from a disk file use the following statement ; where i.e. jquery-1.9.1.js is the file containing the jQuery source ; (or also use a string variable containing the whole jQuery listing) ;~ $oScript.TextContent = FileRead(@ScriptDir & "\jquery-1.9.1.js") ; <--- from a file ; If you want to download jQuery from the web use this statement $oScript.src = 'https://code.jquery.com/jquery-latest.min.js' ; <--- from an url $oIE.document.getElementsByTagName('head').item(0).appendChild($oScript) Do Sleep(250) Until $jsEval("typeof jQuery == 'function'") EndIf Do Sleep(250) $jQuery = $jsEval("jQuery") Until IsObj($jQuery) If $otherlib Then $jsEval('jQuery.noConflict();') Return $jQuery EndFunc ;==>_jQuerify  
    • XaelloNegative
      By XaelloNegative
      Hi there.
      Im having some kind of a coder block here, 
      <td class="treeview ctl00_CenterContent_objTreeView_2" style="white-space:nowrap;"> <input type="checkbox" name="ctl00_CenterContent_objTreeViewn1CheckBox" id="ctl00_CenterContent_objTreeViewn1CheckBox"> <span class="ctl00_CenterContent_objTreeView_0 treeview ctl00_CenterContent_objTreeView_1" id="ctl00_CenterContent_objTreeViewt1" style="border-style:none;font-size:1em;"> <i class="fa fa-file-code-o fa-fw"> </i> <span data-placement="bottom" data-toggle="tooltip" title="" data-original-title="Tool tip for said part">REFUNDS</span></span></td> this is a code directly from the website im working with. I was thinking of inserting a javascript that would get the "REFUNDS" part. Any ideas on how to do so?
      Any thoughts will be highly appreciated.
    • rootx
      By rootx
      1. The script in ie works without errors, why in Autoit does not work?
      2. My goal: I would like to read the contents of the "
      map.panTo(posizione); " variable from the map and save it to a variable in autoit to use it.
      THX.
      PS: you need gmaps API key to execute it locally.
       
      #include-once #include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <IE.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 801, 601, 192, 124) GUISetState(@SW_SHOW) map() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func map() $apikey = "Insert your api key" $html = _ "<!DOCTYPE html>" & @CRLF & _ "<html>" & @CRLF & _ " <head>" & @CRLF & _ " <meta charset=""utf-8"">" & @CRLF & _ " <title>Searchbox</title>" & @CRLF & _ " <style>" & @CRLF & _ " #map {" & @CRLF & _ " height: 100%;" & @CRLF & _ " }" & @CRLF & _ " html, body {" & @CRLF & _ " height: 100%;" & @CRLF & _ " margin: 0;" & @CRLF & _ " padding: 0;" & @CRLF & _ " }" & @CRLF & _ " #map { " & @CRLF & _ " height: 99%; " & @CRLF & _ " width: 99%;" & @CRLF & _ " } " & @CRLF & _ " #pac-input{" & @CRLF & _ " margin: 10 10 10 10;" & @CRLF & _ " width: 200px;" & @CRLF & _ " position: absolute; top: 10px; left: 400px; z-index: 99;" & @CRLF & _ " }" & @CRLF & _ " </style>" & @CRLF & _ " </head>" & @CRLF & _ " <body>" & @CRLF & _ " <div id=""map""></div>" & @CRLF & _ " <script>" & @CRLF & _ "" & @CRLF & _ " function initAutocomplete() {" & @CRLF & _ " var myLatLng = {lat: 41.8956142, lng: 12.5029109}; " & @CRLF & _ " var map = new google.maps.Map(document.getElementById('map'), {" & @CRLF & _ " center: myLatLng," & @CRLF & _ " zoom:15," & @CRLF & _ " mapTypeId: 'roadmap'" & @CRLF & _ " });" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " var markers = [];" & @CRLF & _ " " & @CRLF & _ " map.addListener('click', function(e) {" & @CRLF & _ " placeMarker(e.latLng, map); " & @CRLF & _ " " & @CRLF & _ " });" & @CRLF & _ " " & @CRLF & _ " function placeMarker(position, map) {" & @CRLF & _ " " & @CRLF & _ " var marker = new google.maps.Marker({" & @CRLF & _ " position: position," & @CRLF & _ " map: map " & @CRLF & _ " }); " & @CRLF & _ " var lastpos = position;" & @CRLF & _ " markers.push(marker);" & @CRLF & _ " for (var i = 0; i < markers.length; i++) {" & @CRLF & _ " if (markers[i].getPosition() != lastpos) { " & @CRLF & _ " markers[i].setMap(null);" & @CRLF & _ " markers.splice(i, 1)" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " mapMove(lastpos);" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " function mapMove(posizione){" & @CRLF & _ " map.panTo(posizione);" & @CRLF & _ " alert(posizione);" & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " }" & @CRLF & _ "" & @CRLF & _ " </script>" & @CRLF & _ " <script src=""https://maps.googleapis.com/maps/api/js?key="&$apikey&"&libraries=places&callback=initAutocomplete""" & @CRLF & _ " async defer></script>" & @CRLF & _ " </body>" & @CRLF & _ "</html>" $gmap = _IECreateEmbedded() $gmap_ctrl = GUICtrlCreateObj($gmap, 5, 5, 750, 550) _IENavigate($gmap, "about:blank", 0) _IEDocWriteHTML($gmap, $html) EndFunc <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Searchbox</title> <style> #map { height: 100%; } html, body { height: 100%; margin: 0; padding: 0; } #map { height: 99%; width: 99%; } #pac-input{ margin: 10 10 10 10; width: 200px; position: absolute; top: 10px; left: 400px; z-index: 99; } </style> </head> <body> <div id="map"></div> <script> function initAutocomplete() { var myLatLng = {lat: 41.8956142, lng: 12.5029109}; var map = new google.maps.Map(document.getElementById('map'), { center: myLatLng, zoom:15, mapTypeId: 'roadmap' }); var markers = []; map.addListener('click', function(e) { placeMarker(e.latLng, map); }); function placeMarker(position, map) { var marker = new google.maps.Marker({ position: position, map: map }); var lastpos = position; markers.push(marker); for (var i = 0; i < markers.length; i++) { if (markers[i].getPosition() != lastpos) { markers[i].setMap(null); markers.splice(i, 1) } } mapMove(lastpos); } function mapMove(posizione){ map.panTo(posizione); alert(posizione); } } </script> <script src="https://maps.googleapis.com/maps/api/js?key=yourapikey&libraries=places&callback=initAutocomplete" async defer></script> </body> </html>  
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!