COM_L Inject javascript

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

COM_L Inject javascript

07 Oct 2013, 18:58

Hi,

Using ahk_l COM_l unicode, how do I inject javascript into a webpage.

Both an existing IE webpage and also separately a freshly created Pwb webpage (only has the one tab
at that point) There should be 2 ways.

Thanks
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

07 Oct 2013, 20:13

If you're using AHK v1.1+, then there is no convincing reason to use COM_L over the native COM functionality. As far as executing javascript, you can either navigate to it, or use the execScript method of the window object.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

09 Oct 2013, 08:05

Thanks jethrow.

How you doin? Great to hear from you.

Sorry, I mentioned COM_L to specify I want the AHK_L answer instead of the old AHK basic
version.

So,
myL = alert("something");
Pwb.Document.execScript(myL, "javascript")
This works?

BTW: The link for MS says:
[execScript is no longer supported. Starting with Internet Explorer 11 Preview, use eval. For info, see Compatibility changes.]


The Navigate means I have a script online?

Pwb.Navigate(UrlOfOnlineScript)
how about local script?
Pwb.Navigate("C:/mydir/myjavascript.js")
This works?

Thanks
Zelio
Posts: 278
Joined: 30 Sep 2013, 00:45
Location: France

Re: COM_L Inject javascript

10 Oct 2013, 14:04

Something like this ?

Code: Select all

Gui, Add, ActiveX, w640 h480 vWB, Shell.Explorer
WB.Navigate("about:blank")
Gui, Show
WB.Navigate("javascript: alert('Hello World!')")
else go to http://www.autohotkey.com/board/topic/9 ... e-via-ahk/
or http://www.autohotkey.com/board/topic/4 ... -tutorial/
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

11 Oct 2013, 00:56

Visioneer wrote:How you doin?
I woke up this morning ... so great.
Visioneer wrote:... I mentioned COM_L to specify I want the AHK_L answer instead of the old AHK basic version.
The COM_L library has been depreciated for years since native COM support was introduced, and AHK_L has officially been AHK (v1.1+) since it was upgraded to the official AutoHotkey release.
Visioneer wrote:Pwb.Navigate("C:/mydir/myjavascript.js")
This works?
Adding an external js file to a webpages resources is what you want - and it's not really an AHK question, per se. So, I'll point you to choice 2 on this page: 4 ways to dynamically load external JavaScript(with source)
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

11 Oct 2013, 05:26

Hi,

I don't know guys. In my old basic ahk programming I had a function that
I could feed a "js var" into. The var could be pure javascript and
quite long.

It did not use the address bar or Navgation stuff.

So, say I make a var myL.

Code: Select all

myL =
(
alert("something");
alert(something else";
//a javascript comment
//... a mile long javascript with functions, vars, vars from ahk, document writes, returning vars from webpage, whatever. Millions of js code are available also.
)
This way I can write pure javascript instead of always figuring out
how to do javsascript stuff with COM. Sure COM is nice. But it
takes a long time to figure out a COM way to do everything.
I know the old AHK pretty well, and I know javascript better
than pretty well. The NEW AHK_L not so much. Especially the
AHK_L native COM.

This is the call I used for this basic "old deprecated ahk" function.
IE_InjectJS(WinExist("ahk_class IEFrame"), myL)
or
IE_InjectJS(myHwnd, myL)
or
myReturnVar := IE_InjectJS(WinExist("ahk_class IEFrame"),"document.activeElement.focus();", "document.title,document.activeElement.tagName")
(this would run some js code, and even get 1 or more vars back from the webpage whose
values could be obtained like this:

Code: Select all

Loop, Parse, myReturnVar, `,
{
if A_Index = 1
myVar1 = %A_LoopField%
if A_Index = 2
myVar2 = %A_LoopField%
}
;MsgBox, 4096,, myVar1 is: %myVar1%`nmyVar2 is: %myVar2%, 5
So a function like this gives you infinite, easy, quick, javascript in any IE webpage,
even a preexisting one.

Well worth the time to make such a function.

It simply used the main webpage tab. The webpage was created with old COM and only had the one
tab at the start. Actually it had a way of dealing with tabs as I recall.

I see lots of articles on the AHK forums about doing this with old ahk,
but it's always a run around to do something like this with the
NEW and IMPROVED AHL_L. I am only looking for a COM (IE) solution which
only opens an IE browser page anyway.

I can post the old ahk function if you wish.

Thanks

ps: I will get into local js files later. This is for js code in the ahk script itself.

Moderator: please use code tags when posting code.
Last edited by Visioneer on 11 Oct 2013, 06:37, edited 1 time in total.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: COM_L Inject javascript

11 Oct 2013, 06:19

the "IE_InjectJS" by ahklerner. Uses execscript() but it also Query's for the ParentWindow of the IE control to get the javascript variables

Im not that big on js but when i see something in js for IE, it seem like im able to use it right away with AHK 1.1
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

11 Oct 2013, 06:31

Hi,

Here is an old paste of this function. It needs a little clean up of my custom
notes and stuff. It should work as is in old ahk. It has served me very well over the
years. I would like something just like this in NEW AHK_L so I could use
some of my old calls as much as possible. I did not write this. I adapted it from ahklerner
and from several posts and got some help on fixing up from jethrow and others I seem
to recall. With this I can also use online .js files, and local .js files on my PC. I mean some
humongous js files. It required an include at one point I believe ACC.ahk, and of course
COM.ahk.

[Block] was a var I used to "return" block hotkeys while certain things were happening.
[fURL] was a var I used for most URLs.
[myProg] was a var of my program's name.

Code: Select all

IE_InjectJS(hWnd_MainWindow, JS_to_Inject, VarNames_to_Return="", JS_to_Invoke1="", JS_to_Invoke2="") 
{ 
global Block, fURL, myProg
;FixSilent

;MsgBox, 4096,, fURL is: %fURL%, 2 

;theURL := IE_InjectJS(hwnd, "", "document.location.href")
;return theURL

;MsgBox, 4096,, hWnd_MainWindow is: %hWnd_MainWindow%`nJS_to Inject is: %JS_to_Inject%`nVarNames_to_Return is: %VarNames_to_Return%`nJS_to_Invoke1 is: %JS_to_Invoke1%`nJS_to_Invoke2 is: %JS_to_Invoke2%

;Prevent running again before this one is finished. (Crashes XP)
if Block = ON
KeepBlock = ON
Block = ON

IfWinNotExist, ahk_id %hWnd_MainWindow%
{
;MsgBox, 4096,, hWnd_MainWindow does not exist`nhWnd_MainWindow is: %hWnd_MainWindow%`n`JS_to Inject is: %JS_to_Inject%`nVarNames_to_Return is: %VarNames_to_Return%`nJS_to_Invoke1 is: %JS_to_Invoke1%`nJS_to_Invoke2 is: %JS_to_Invoke2%
if KeepBlock =  
Block =
return
}

myTries = 0
IE_InjectJS2:

;Get a list of the hWnd's owned by the window specified 
WinGet, ActiveControlList, ControlListhWnd, ahk_id %hWnd_MainWindow% 
;MsgBox, 4096,, ActiveControlList is: %ActiveControlList%`nmyTries is: %myTries%, 3
 
;Go throught the list 1 at a time to determine if it is the correct control 
;This will allow the script to find the current tab in IE7+ 
Loop, Parse, ActiveControlList, `n 
{ 
;Get the classname of the current control 
WinGetClass, ThisWinClass, ahk_id %A_LoopField% 
;If the classname is correct and it is visible, it is the correct tab 

If ThisWinClass = AVL_AVVIEW
{ 
if KeepBlock =  
Block =
return
}

If (ThisWinClass = "Internet Explorer_Server") and (DllCall("IsWindowVisible", UInt, A_LoopField)) 
{	   
hIESvr := A_LoopField 
break
}
}

;If a control was not found, sleep, 200 and try 10 times, then return and doing nothing.
If !hIESvr 
{ 
myTries++
;MsgBox, 4096,, Control "Internet Explorer_Server" not found.`nA_ThisHotkey is: %A_ThisHotkey%`nA_PriorHotkey is: %A_PriorHotkey%`nA_ThisLabel is: %A_ThisLabel%`nA_ThisFunc is: %A_ThisFunc%
sleep, 500 	  
if myTries = 10
{
if KeepBlock =  
Block =
return 
}
Gosub, IE_InjectJS2         
return
}
;MsgBox, 4096,, hIESvr is: %hIESvr%`nhWnd_MainWindow is: %hWnd_MainWindow%, 3

;Initialize the COM interface. code modified from SEAN 
IID_IHTMLWindow2   := "{332C4427-26CB-11D0-B483-00C04FD90119}" 
    
COM_AccInit()
;COM_Init()

;COM_Error(False)
;COM_Error(True)

pacc := COM_AccessibleObjectFromWindow(hIESvr) 
if !pacc
{
;WinGetTitle, myTitle, ahk_id %hWnd_MainWindow%
;MsgBox, 4096,, pacc does not exist`nmyTitle is: %myTitle%`nhWnd_MainWindow is: %hWnd_MainWindow%`nJS_to Inject is: %JS_to_Inject%`nVarNames_to_Return is: %VarNames_to_Return%`nJS_to_Invoke1 is: %JS_to_Invoke1%`nJS_to_Invoke2 is: %JS_to_Invoke2%`nhIESvr is: %hIESvr%, 4
COM_AccTerm()
if KeepBlock =  
Block =
return
}

pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2) 
COM_Release(pacc)

if !pwin
{
;WinGetTitle, myTitle, ahk_id %hWnd_MainWindow%
;MsgBox, 4096,, 1 pwin does not exist`nmyTitle is: %myTitle%`nhWnd_MainWindow is: %hWnd_MainWindow%`nJS_to Inject is: %JS_to_Inject%`nVarNames_to_Return is: %VarNames_to_Return%`nJS_to_Invoke1 is: %JS_to_Invoke1%`nJS_to_Invoke2 is: %JS_to_Invoke2%`nhIESvr is: %hIESvr%, 4
COM_AccTerm()
if KeepBlock =  
Block =
return
}

IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}" 
pwb := COM_QueryService(pwin,IID_IWebBrowserApp,IID_IWebBrowserApp) 
Com_Release(pwin) 

if !pwb
{
;WinGetTitle, myTitle, ahk_id %hWnd_MainWindow%
;MsgBox, 4096,, pwb does not exist`nmyTitle is: %myTitle%`nhWnd_MainWindow is: %hWnd_MainWindow%`nJS_to Inject is: %JS_to_Inject%`nVarNames_to_Return is: %VarNames_to_Return%`nJS_to_Invoke1 is: %JS_to_Invoke1%`nJS_to_Invoke2 is: %JS_to_Invoke2%`nhIESvr is: %hIESvr%, 4
COM_AccTerm()
if KeepBlock =  
Block =
return
}

pwin := COM_QueryService(pwb,IID_IHTMLWindow2,IID_IHTMLWindow2) 
;Com_Release(pwb)

if !pwin
{
;WinGetTitle, myTitle, ahk_id %hWnd_MainWindow%
;MsgBox, 4096,, 2 pwin does not exist`nmyTitle is: %myTitle%`nhWnd_MainWindow is: %hWnd_MainWindow%`nJS_to Inject is: %JS_to_Inject%`nVarNames_to_Return is: %VarNames_to_Return%`nJS_to_Invoke1 is: %JS_to_Invoke1%`nJS_to_Invoke2 is: %JS_to_Invoke2%`nhIESvr is: %hIESvr%, 4
Com_Release(pwb)
COM_AccTerm()
;COM_Term()
if KeepBlock =  
Block =
return
}

;MsgBox, 4096,, fURL is: %fURL%`nJS_to_Invoke1 is: %JS_to_Invoke1%, 2
;FixSilent

If JS_to_Invoke1 = Load
{
JS_to_Invoke1 =
COM_Invoke(pwb, "Silent=", "False")
}
else
{
;COM_Invoke(pwb, "Silent=", "True")

;FixDebug
;soundbeep
COM_Invoke(pwb, "StatusBar=", false)
COM_Invoke(pwb, "StatusText=", false)

}

if fURL not contains %myProg%
{
COM_Invoke(pwb, "Silent=", "True")
}


;Execute the Javascript (if there is any).
If JS_to_Inject 
{
;MsgBox, 4096,, JS_to Inject is: %JS_to_Inject%, 4
COM_Invoke(pwin, "execscript", JS_to_Inject) 
}   	  

If JS_to_Invoke1 
{
;MsgBox, 4096,, JS_to_Invoke1 is: %JS_to_Invoke1%, 4
COM_Invoke(pwb, JS_to_Invoke1) 
}   	  

;Get the value of the variables, if any. 
If VarNames_to_Return { 
;MsgBox, 4096,, VarNames_to_Return is: %VarNames_to_Return%, 3

;Split the passed variable names into a psuedo array of ahk variables 
StringSplit, Vars_, VarNames_to_Return, `, 

;Get the value of each javascript variable in the order it was passed 
Loop, %Vars_0% 
{
;MsgBox, 4096,, Vars_%A_Index% is: Vars_%A_Index%, 3
Ret .= COM_Invoke(pwin,Vars_%A_Index%) . "," 
;MsgBox, 4096,, Ret is: %Ret%, 3
}
;Remove the trailing comma 
StringTrimRight, Ret, Ret, 1 
}

If JS_to_Invoke2 
{
;MsgBox, 4096,, JS_to_Invoke2 is: %JS_to_Invoke2%, 4
COM_Invoke(pwb, JS_to_Invoke2) 
}   	
	  
;Cleanup 
COM_Release(pwb)
COM_Release(pwin) 
COM_AccTerm()
;COM_Term()
   
if KeepBlock =  
Block =

;MsgBox, 4096,, Ret is: %Ret%, 3
;Return a comma seperated list of variables in the order they were passed. 
Return Ret 
}
Thanks
Last edited by Visioneer on 11 Oct 2013, 08:12, edited 1 time in total.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

11 Oct 2013, 08:09

Yes Holyblackman, that is one of the posts I saw years ago. There were several others. BTW: I never had to put the "javascript:" part with what I wound up with.

You can see what a rage it was back in the day. let us make the NEW improved AHK_L
catch up with old AHK basic. A clone function would allow many older calls to that
very popular functon to be more easily ported to the new fabulous AHK_L, (or whatever you
call it these days).

Thanks
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

11 Oct 2013, 22:17

Visioneer wrote:

Code: Select all

myL =
(
alert("something");
alert(something else";
//a javascript comment
//... a mile long javascript with functions, vars, vars from ahk, document writes, returning vars from webpage, whatever. Millions of js code are available also.
)
This way I can write pure javascript instead of always figuring out
how to do javsascript stuff with COM. Sure COM is nice. But it
takes a long time to figure out a COM way to do everything.
I know the old AHK pretty well, and I know javascript better
than pretty well.
The NEW AHK_L not so much. Especially the
AHK_L native COM.
I'm throwing down a challenge on the statement in red ... :twisted:
I'm going to claim that you're too well versed (or dependent) in AHK Basic to appreciate how similar AHK v1.1+ code is to javascript code :shock:

Code: Select all

Gui, Add, ActiveX, w800 h800 vwb, Shell.Explorer
wb.Navigate("http://www.auto-hotkey.com/boards/viewtopic.php?f=5&t=182")
Gui, Show
while wb.busy
	sleep 10
window := wb.document.parentWindow
return

F1::
myL =
(
alert("something");
alert("something else");
//a javascript comment
//... a mile long javascript with functions, vars, vars from ahk, document writes, returning vars from webpage, whatever. Millions of js code are available also.
)
	window.execScript(myL)
	return

GuiClose:
	ExitApp
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

12 Oct 2013, 10:47

Thanks jethrow,

I am speechless. I accept any challange you make. I am always in awe of your
abilities and kindness. Here is a start on ahklerner's function in AHK_L. I guess I don't
have the words to explain to you that miles of already existant javascript do not,
and should not, have to be re-expressed in AHK_L or anything else as they already
have been written and time tested. Plus externel js files do not even belong
in the script at all. BTW, I often grab just the js code itself from a server or local js
file so I do not need the Navagate stuff anyway.

What I need is a HWND function I can use hunderds of times.

BTW: I don't know much about using this forum and maybe it's just me,
but I find it a pain copying parts or entire code sections with those
numbers 1. 2. 3. etc. I have to delete all those numbers and it discourages
me from even bothering sometimes. Is there a way to copy some code without
those numbers being included? Can those numbers just not be included in the
first place? The way it is now, it is not the same code I posted. :D

Thanks jethrow,

Code: Select all

F1::
;this function should work with any existent IE window, so I am not
;including it's creation here.

myL =
(
alert("something");
//a javascript comment
//... a mile long javascript with functions, vars, vars from ahk, document writes, returning vars from webpage, whatever. Millions of js code are available also.
document.activeElement.focus();
)

;This should run myL javascrpt, and return 2 comma delimited vars, document.title and
document.activeElement.tagName in variable myReturnVar 

myReturnVar := IE_InjectJS(WinExist("ahk_class IEFrame"),myL, "document.title,document.activeElement.tagName")

Loop, Parse, myReturnVar, `,
{
if A_Index = 1
myVar1 = %A_LoopField%
if A_Index = 2
myVar2 = %A_LoopField%
}
;MsgBox, 4096,, myVar1 is: %myVar1%`nmyVar2 is: %myVar2%, 5

return

;The function
IE_InjectJS(hWnd_MainWindow, JS_to_Inject, VarNames_to_Return="", JS_to_Invoke1="", JS_to_Invoke2="") 
{ 
;global Block, fURL, myProg  not needed right now

;Should work with top existant IE window. HWND  WinExist("ahk_class IEFrame")
;so no need to create the window in the function itself. Use only hWnd_MainWindow (HWND)

;JS_to_Inject myL is fed to the function 

;HWND
;execScript to apply myL  to hWnd_MainWindow HWND here       
;we will worry about the tabs later.

;Get the value of the variables, if any. 
If VarNames_to_Return { 
;MsgBox, 4096,, VarNames_to_Return is: %VarNames_to_Return%, 3
;Split the passed variable names into a psuedo array of ahk variables 
StringSplit, Vars_, VarNames_to_Return, `, 
;Get the value of each javascript variable in the order it was passed 
Loop, %Vars_0% 
{
;MsgBox, 4096,, Vars_%A_Index% is: Vars_%A_Index%, 3

;Ret .= applied to pwin(HWND) here.
;Ret .= COM_Invoke(pwin,Vars_%A_Index%) . "," 

;MsgBox, 4096,, Ret is: %Ret%, 3
}
;Remove the trailing comma 
StringTrimRight, Ret, Ret, 1 
}

;We can do JS_to_Invoke1 and JS_to_Invoke2 later.

;Ret  is the comma delimited vars from VarNames_to Return"
Return Ret 
)

GuiClose:
ExitApp
Moderator: please use code tags when posting code.
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

12 Oct 2013, 13:39

Code: Select all

wb := WBGet()  ; www.autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
document := wb.document
window := document.parentWindow

window.alert("something")
document.activeElement.focus()

MsgBox %  "Document Title: " document.title
	.	"`nActive TagName: " document.activeElement.tagName
... & this should also partially answer you question from the other forum:
... how do I get a variable's value that exists in that same webpage?
... though recent versions of IE have not allowed direct access to variables stored in the window object.
Visioneer wrote:... I find it a pain copying parts or entire code sections with those
numbers 1. 2. 3. etc. I have to delete all those numbers and it discourages
me from even bothering sometimes. Is there a way to copy some code without
those numbers being included?
Are you actually able to copy those numbers? Chrome (Iron 29) will select but not copy them, and FF (22) & IE (10) won't even select them.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

12 Oct 2013, 16:59

Thanks jethrow,

I am using W7 with IE 9, but sometimes I use compatibility mode IE7 I guess.
I get the numbers with partial copying or Select all. Not the download.
Also it appears to not select them. in other words they do not turn blue,
but the numbers show up in the paste.

Now jethrow,



jethrow,


If I tell you that myL VARIABLE can come from my server or my hard drive, and be
23000 lines long, that's lines not characters, and I can update those js files at anytime.
are you still satisfied with your answer.?

If you are still taking myL example contents literally, I can give you a link to ahk_l variables.

Now if you are saying:

Code: Select all

wb := WBGet()  
document := wb.document
window := document.parentWindow
/*
this would be the same as 
WinExist("ahk_class IEFrame")?, the HWND?,  I would prefer an HWND
reference because I can control that in the function call. In other words I
can specify the HWND. It might not be WinExist("ahk_class IEFrame"),
it might be a specific HWND to a not active window for example.  
*/
window.execScript(myL), or window.execScript(JS_to_Inject),
OR
document.execScript(myL), or document.execScript(JS_to_Inject).
Then that would be very helpful.
Are you are saying any of these?

And I do not see what you mean about AHK_L can't get the value
of a variable in a webpage. The old ahk could. Maybe you and Lexicos
could add that feature? I seem to remenber you fixing that problem for
me years ago in the old AHK ahklerner function I have posted here above.
Was that the special ability of the acc.ahk add on?

Thanks
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

12 Oct 2013, 17:15

Visioneer wrote:If I tell you that myL VARIABLE can come from my server or my hard drive, and be
23000 lines long, that's lines not characters, and I can update those js files at anytime.
are you still satisfied with your answer.?
Again, are you talking about executing javascript, or including js files in the resources for a page?
I would prefer an HWND
reference because I can control that in the function call.
If you look at the WBGet function, it uses the same WinTitle-type parameter as WinExist(). So, you can do this:
wb := WBGet("ahk_id" HWND)
window.execScript(myL), or window.execScript(JS_to_Inject),
OR
document.execScript(myL), or document.execScript(JS_to_Inject).
Then that would be very helpful.
Are you are saying any of these?
This is one area I'm challenging your js/html/dom knowledge. The document object doesn't have an execScript method -- but yes, the window object does.
And I do not see what you mean about AHK_L can't get the value
of a variable in a webpage. The old ahk could.
You are still missing the fact that AHK v1.1+ is an upgrade - including all COM functionality. So, if it could be done in AHK Basic, it can typically be done in AHK v1.1 easier. As I said, newer versions of IE ... however ...

... I didn't do enough testing. I must not have had the correct permissions on webpage when I tested earlier:

Code: Select all

wb := WBGet()

IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb, IID, IID),1)

window.execScript("foo='bar'")
MsgBox % window.foo
IMPORTANT: On a side note, I may update the WBGet & IEGet functions. I'm thinking of switching them, and then allowing IEGet (currently WBGet) the optionally return the window, document, or webbrowser object.
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

12 Oct 2013, 21:08

Hi jethrow,
Again, are you talking about executing javascript, or including js files in the resources for a page?
Again? As the Highwayman song goes, I'll be back again and again and again...
Both.
In the simplest form the alert box will show up with no help. In my more complex
form(s) I get the actual code from my server files/local files and inject that. The function
knows only the JS_to_Inject function parameter var.

Don't get mad teach, but I am getting a "Call to non existant function" (No, not the wife)
with wb := WBGet("ahk_id" hWnd_MainWindow) or wb := WBGet()

MsgBox, % A_AhkVersion ;reads: 1.1.13.00

So:
window.execScript(JS_to_Inject) ;it shall be by golly!
IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb, IID, IID),1)
Sorry, I can't resist. ROTHFLMFAO ;and I am pretty skinny
I always fail the tests. That's why I am an AHK_L junior cadet programmer I guess.
version 1.1.13.00 mind you. er. Make that v1.1+ sir.
window.execScript("foo='bar'")
MsgBox % window.foo
Is that supposed to be getting a var or a bar from the webpage?
I could not get that far because of the WBGet() errar.
Somewhere there has to be a Ret .= thing eventually happening right?

Like I always say, it's gotta work once in a row before I foist it on people.

Thanks
Last edited by Visioneer on 12 Oct 2013, 23:08, edited 1 time in total.
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

12 Oct 2013, 22:23

Visioneer wrote:Both.
I think you either don't understand what you don't understand, or you're trying to walk & chew gum at the same time. I'm going to ignore the code you posted before which implied you wanted to add a js file to the webpages resourses -- & assume you only want to execute javascript code.
Don't get mad teach, but I am getting a "Call to non existant function"
I believe that means the function doesn't exist. If you go the the URL I put in the comments on the first reference to WBGet, you will be able to find the function defenition.

Code: Select all

IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb, IID, IID),1)
Sorry, I can't resist. ROTHFLMFAO ;and I am pretty skinny
I always fail the tests. That's why I am an AHK_L junior cadet programmer I guess.
I assume you mean that code is difficult to understand :?: If so, you should see the corresponding code in AHK Basic :twisted: :lol:
(that's why people create UDFs - so you don't have to see/write all the complex back-end code)
window.execScript("foo='bar'")
MsgBox % window.foo
Is that supposed to be getting a var or a bar from the webpage?
Well, it executes the javascript foo='bar', then extracts the value of foo (variable in the window object) from the window object. Note, I'm again challenging your js/html/dom knowledge here.
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: COM_L Inject javascript

12 Oct 2013, 22:27

he said udf

Image
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
joedf
Posts: 8951
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: COM_L Inject javascript

12 Oct 2013, 22:51

nice one tank... hahahah haha :P
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Visioneer
Posts: 140
Joined: 07 Oct 2013, 18:51

Re: COM_L Inject javascript

13 Oct 2013, 01:01

Yes jethrow,

Please let us please just clone the old IE_Inject function. When I grab the js code
from files, it is just a big execScript, which amounts to about the same thing.
I mean if I can place 23000 lines of js code in the webpage who cares if I chew
gum. You can ingnore anything you like of what I said before, but NOT the function
or it's usefulness and popularity.

So you want me to add a function called WBGet() which is spelled out in:
http://www.autohotkey.com/board/topic/4 ... -tutorial/ ?
er. HUM! :roll:

Forget about the
IMPORTANT: On a side note, I may update the WBGet & IEGet functions. I'm thinking of switching them, and then allowing IEGet (currently WBGet) the optionally return the window, document, or webbrowser object.
side note?
Is the next version of ahk_l what we need to wait for?

As far as the Ret .= thing goes you are saying:
If VarNames_to_Return {
StringSplit, Vars_, VarNames_to_Return, `,
Loop, %Vars_0%
{
Ret .= window.Vars_%A_Index%) . ","
}
StringTrimRight, Ret, Ret, 1
}
would work?
I assume you mean that code is difficult to understand If so, you should see the corresponding code in AHK Basic
Hard? No it's the old:
IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb, IID, IID),1)

It is a miracle how easy you have made the new and improved ahk_l

What is hard for me to understand is why it has been so difficult to advance the
power of v1.1+ by getting this very powerful function converted and posted.
"Run around" does not begin to describe it. You guys used to love this function,
and so did many others. I think I asked a very appropriate question. It turns
out that the answers are a far far cry from the original answers I have gotten
before. It is not the trivial stuff of simpletons like you made it out to be.
It will take the best efforts of a true genius like yourself to get it done correctly.
I am just so greatful you are taking the time to help a dummy like me get the
vision accomplished for everyone's sake.

The fact that WBGet() is missing and you did not know it, and you think my
challange is to find it myself, and add it myself, is not difficult to understand.
This stuff is so complex. You are not a machine for god sakes. Why can't
they just... just... be satisfied with the nice forum. You show them how
to do javascript statements using the built-in COM. Yes. That's the ticket.
It must be lonely at the top. You never know how something works until you
try to show it to your friends.

You give a man a fish yada yada...

Thanks

hey tank, bless you for making this great new forum. Thanks.
Anything improved in the search you can make a separate post on?
Now jethrow can monitor my stupidity on two forums. :D
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM_L Inject javascript

13 Oct 2013, 01:22

Visioneer wrote:Please let us please just clone the old IE_Inject function
Why didn't you just ask this to begin with? I thought you actually were interested in understanding these concepts. I guess my mind reading isn't as good as it used to be ... or perhaps trying to get through the pool of sarcasm is slowing me down a bit.

But to sober this topic a bit, I on purpose don't spoon-feed 100% of the answer to questions ... this helps determine how to best help the user. For instance, in your case, if you are having trouble identifying that you're missing a UDF, then that gives everyone a indicator of how to best help you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, OrangeCat, ShatterCoder and 86 guests