Including External Javascript Code

Monkey Targets Forums/HTML5/Including External Javascript Code

c.k.(Posted 2012) [#1]
If I have an external javascript lib, say, "http://webui.social.playphone.com/web_mnsapi/MNDirectHost.js.php," how do I get that included in my monkey project build? The line in the HTML file has to say something like,

<script type="text/javascript" src="http://webui.social.playphone.com/web_mnsapi/MNDirectHost.js.php"></script>



therevills(Posted 2012) [#2]
Not sure if this will work, but you could try this:

Monkey File:
[monkeycode]Strict

Import "extern.js"

Public

Function Main:Int()
Print "Start"
Return 0
End[/monkeycode]

extern.js:
document.write("<script src='http://webui.social.playphone.com/web_mnsapi/MNDirectHost.js.php'><\/script>");


This does add the script to the file and then of course you will need to extern the functions.


c.k.(Posted 2012) [#3]
I think the <script src...> tag will need to be in MonkeyGame.html, so I guess the monkey builder needs to know to put it in there. Will what you've suggested do that?

I guess I could always just put it in there manually too.


therevills(Posted 2012) [#4]
It will get added to the main.js file:

Generated Monkey code:
document.write("<script src='http://webui.social.playphone.com/web_mnsapi/MNDirectHost.js.php'><\/script>");
function bbMain(){
	push_err();
	print("Start");
	pop_err();
	return 0;
}
function bbInit(){
}
//${TRANSCODE_END}


The document.write command will add it to the DOM and you will be able to access the external commands.


c.k.(Posted 2012) [#5]
Cool! I'll give it a shot. Thanks!