AutoHotkey Community

It is currently May 27th, 2012, 1:01 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: November 11th, 2011, 4:54 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
It seems that PHP html_entity_decode will fall short on certain
characters like ’ (right quote) for example. I have read
that Javascript could be used instead with something like:
Code:
var temp=document.createElement("pre");
temp.innerHTML=string;
return temp.firstChild.nodeValue;


So I was thinking that a function that would create a hidden
Internet Explorer instance (IE-6-9) and would in-take:
JS_to_Inject, VarNames_to_Return=""
via execScript
and/or optionally
Com_JS_to_Invoke, VarNames_to_Return=""
would be a neat way to do such things as just using
Javascript to operate on strings, arrays, and other things.

Thanks to Jethrow, tank & Sean for inspiring the idea.

I would like to see a function in AHK basic and AHK_L

Thanks


Last edited by Visioneer on November 11th, 2011, 7:27 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2011, 7:19 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
OK, I have tried the idea with an existant IE window and it does
work. The ’ returns a right quote.
Code:
F6:
string = Micheal’s Quote
myV =
(
var temp=document.createElement("pre");
temp.innerHTML="%string%";
var myTest = temp.firstChild.nodeValue;
)
myVar := IE_InjectJS(WinExist("ahk_class IEFrame"), myV, "myTest")
return


Now I want to do this with a new Created hidden IE instance.
eg:
Code:
F6:
string = Micheal’s Quote
myV =
(
var temp=document.createElement("pre");
temp.innerHTML="%string%";
var myTest = temp.firstChild.nodeValue;
)
myVar := JSInvoke(myV, "", "myTest")
return


with a function JSInvoke something like:
Code:
JSInvoke(JS_to_Inject="",Com_JS_to_Invoke="",VarNames_to_Return="")
{
Com_Init()
pwb := COM_CreateObject("InternetExplorer.Application")
;COM_Invoke(pwb, "Visible=", "False") ;"False" ;"True" ;  Hidden by default, so not needed?

;How to get the pwin for Created IE. IE6,7,8 & 9

If JS_to_Inject
COM_Invoke(pwin, "execscript", JS_to_Inject)

;This is less inportant right now.
;If Com_JS_to_Invoke
;COM_Invoke(pwb, Com_JS_to_Invoke)
;If Com_JS_to_Invoke
;COM_Invoke(pwin, Com_JS_to_Invoke)


;Get the value of the variables, if any.
If VarNames_to_Return {
;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%
Ret .= COM_Invoke(pwin,Vars_%A_Index%) . ","
;Remove the trailing comma
StringTrimRight, Ret, Ret, 1
}

;OK?
COM_Invoke(pwb, "Quit")
Com_Release(pwb)

Com_Release(pwin)
Com_Term()
 
;Return a comma seperated list of variables in the order they were passed
Return Ret
}

There are 3 questions in the above code.
I need ank BASIC version.

Thanks


Last edited by Visioneer on November 12th, 2011, 8:24 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 11th, 2011, 9:46 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
AHK_L example:
Code:
Document := ComObjCreate("HtmlFile")
Document.Write("Micheal’s Quote")
MsgBox, % Document.body.innerText

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2011, 2:34 am 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Great Jethrow. How about the ahk basic function/questions?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2011, 7:52 am 
Offline
User avatar

Joined: May 24th, 2009, 5:35 am
Posts: 2099
Location: Iowa, USA
I suggest you change you approach. Here's an AHK Basic version:
Code:
Com_Init()

Document := Com_CreateObject("HtmlFile")
Com_Invoke(Document, "Write", "Micheal’s Quote")
MsgBox, % Com_Invoke(Document, "body.innerText")

Com_Release(Document), Com_Term()

_________________
Image
Recommended: AutoHotkey_L
Basic Webpage Controls


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2011, 10:32 pm 
Offline

Joined: November 19th, 2007, 4:59 pm
Posts: 144
Thanks Jethrow,
That works. I guess I'll just add a function to use this.

The other way could be a function for many other uses like running Jscript
on demand and getting vars/arrays from it. But this is all I really need
for this job.

Many Thanks.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group