want to add jquery to an activex control

Get help with using AutoHotkey and its commands and hotkeys
haichen
Posts: 158
Joined: 09 Feb 2014, 08:24

want to add jquery to an activex control

15 May 2015, 05:05

But i didnt even get this to work:

Code: Select all

html =
(
<html><head>
<script src="helloworld.js"></script>

</head><body>
<button onclick="ClickFunction()">Try it</button>
</body></html>
)

Gui, Add, ActiveX,  w200 h50 vwb, shell.explorer
wb.NAvigate("about:blank")
wb.document.open()
wb.document.write(html)
wb.document.close
Gui, Show ,x200

Gui , 2:Add, ActiveX,  w200 h50 vWB1, HTMLFile
wb1.write(html)
Gui, 2:Show ,x500
return
*/
GuiClose:
ExitApp
if i use

Code: Select all

html =
(
<html><head><title></title>

<script>function ClickFunction(){alert("Hello World!");}</script>

</head><body>
<button onclick="ClickFunction()">Try this </button>
</body></html>
)
it works.
I tried local file uri like file:///C:/... and server url (for jquery) like <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
I hope someone can give me a hint.
lexikos
Posts: 6256
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: want to add jquery to an activex control

15 May 2015, 06:04

I don't see why file:///full_path wouldn't work.

//some_url uses the protocol of the current document.
helloworld.js is relative to the current document.

But where is the current document? It's at about:blank, of course.
haichen
Posts: 158
Joined: 09 Feb 2014, 08:24

Re: want to add jquery to an activex control

15 May 2015, 08:22

Thank you very much Lexikos!
I think there was something wrong with my full Path to the js file.

Here is some small working example:

Code: Select all

/*
 hellojquery.js :

$(document).ready(function() {  
	$( "div" ).hide();
    $( "a" ).click(function( event ) {
        alert( "As you can see, the link no longer took you to jquery.com" );
        event.preventDefault();
    });
}); 

*/

html =
(
<!doctype html>
<html>
<head>
	<title>Demo</title>
	<script src="file:///C:/Users/haichen/Documents/jquery/jquery.js"></script>
	<script src="file:///C:/Users/haichen/Documents/jquery/hellojquery.js"></script>	
</head>

<body>
<div>hallo jquery</div>
<p>there should be no div hallo</p>
<a href="http://jquery.com/">jQuery</a>    
</body>
</html>
)

 
Gui, Add, ActiveX, w500 h500 vwb, shell.explorer
wb.NAvigate("about:blank")
wb.document.open()
wb.document.write(html)
wb.document.close

source:=wb.document.getElementsByTagName("html")[0].innerhtml
gui, show

msgbox, % source
return

guiclose:
document.write("")
document.close
ExitApp
return
lexikos
Posts: 6256
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: want to add jquery to an activex control

15 May 2015, 20:03

FYI, your control will probably always be in IE7 mode (wb.Document.documentMode == 7). You can fix that by replacing about:blank with about:<meta http-equiv='X-UA-Compatible' content='IE=edge'>.
haichen
Posts: 158
Joined: 09 Feb 2014, 08:24

Re: want to add jquery to an activex control

16 May 2015, 03:18

Aaah, wonderful.
At the moment i try to add the scriptfiles with this.

Code: Select all

jqscript := wb.document.createElement("script")
jqscript.src := "%A_ScriptDir%/hellojquery.js"
s:=wb.document.getElementsByTagName("script")[0]
parentNode.appendChild(jqscript,s)
s.appendChild(jqscript
I think i dont understand the different Activx-controls. With htmfile (without wb.) i can add the scripts like above.
where is the difference? I thougth wb is the whole window (with the document) and htmfile is only the document with the DOM. But thats wrong i suppose.
lexikos
Posts: 6256
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: want to add jquery to an activex control

16 May 2015, 03:41

Your code seems to be broken/incomplete.
  • Firstly, I assume you're using v2 since you've used a variable in a quoted string.
  • Why get an existing script element (s) from the document? What if the document doesn't have any?
  • What is parentNode?
  • appendChild() only takes one parameter, but you're passing two. Did you mean to use insertBefore()?
  • I can't imagine what the second (broken) appendChild() call is for.
This works for me (with Shell.Explorer):

Code: Select all

s := wb.document.createElement("script")
s.type := "text/javascript"
s.src := A_ScriptDir "\test.js"
wb.document.getElementsByTagName("head")[0].appendChild(s)
htmlfile is just a HTMLDocument object (MSHTML) without the browser control hosting it. I'm not sure what the differences are exactly, but I think it's less functional than Shell.Explorer.
haichen
Posts: 158
Joined: 09 Feb 2014, 08:24

Re: want to add jquery to an activex control

16 May 2015, 04:42

Sorry for the nonfunctional code.
I tried it again and the strange s.parentNode.appendChild(Script, s) works therein:

Edit: Works also s.parentNode.appendChild(Script)
I found it at http://www.html-seminar.de/javascript-d ... reifen.htm

Code: Select all

/*
 hellojquery.js :

$(document).ready(function() {  
	$( "div" ).hide();
    $( "a" ).click(function( event ) {
        alert( "As you can see, the link no longer took you to jquery.com" );
        event.preventDefault();
    });
}); 


<script src="%A_ScriptDir%/hellojquery.js"></script>	
*/


html =
(
<!doctype html>
<html>
<head>
    <title>Demo</title>
    <script src="%A_ScriptDir%/jquery.js"></script>
	
</head>

<body>
<div>hallo jquery</div>
<p>there should be no div hallo</p>
<a href="http://jquery.com/">jQuery</a>    
</body>
</html>
)

 
Gui, Add, ActiveX, w500 h500 vwb, shell.explorer
;wb.NAvigate("about:<meta http-equiv='X-UA-Compatible' content='IE=edge'>")
;only ie7 works
wb.NAvigate("about:blank")
wb.document.open()
wb.document.write(html)
wb.document.close

jqscript := wb.document.createElement("script")
jqscript.src := A_ScriptDir . "/hellojquery.js"
s:=wb.document.getElementsByTagName("title")[0]
s.parentNode.appendChild(jqscript, s)

source:=wb.document.getElementsByTagName("html")[0].innerhtml
wb.document.close
gui, show
msgbox, % source 
return

guiclose:
ExitApp
return
lexikos
Posts: 6256
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: want to add jquery to an activex control

16 May 2015, 05:30

haichen wrote:Works also s.parentNode.appendChild(Script)
Of course it does - that's the correct usage. Any other parameters you pass are meaningless.
s:=wb.document.getElementsByTagName("title")[0]
s.parentNode.appendChild(jqscript, s)
So now instead of failing if there's no script element, the code will fail if the document has no title. You should just "use your head" like I showed. :lol:
I found it at ...
I wouldn't rely on that site any further, if I were you.
haichen
Posts: 158
Joined: 09 Feb 2014, 08:24

Re: want to add jquery to an activex control

16 May 2015, 06:03

Sometimes i loose my head... :D

Return to “Ask For Help”

Who is online

Users browsing this forum: Kobaltauge, Milchmann, RyanAyton, swagfag, yduck and 149 guests