Calling a function from outside of the Hype scripts but inside the same html document!

Hi there Hype gurus.

I want to know what is the proper syntax for calling a function/script in the same html file as my Hype code. I have to put all the code in one single file. No external files. So I export everything from Hype into a single html file. If there is a external JS, I copy that into the single file as well. Here is the function that needs to operate OUTSIDE of the Hype code. I need to put this function in the html head /head /html portion of my stand alone file (if that will work)...

[script]
function appstore() {
if(navigator.userAgent.indexOf("Android") != -1){
mraid.open("https://play.google.com/store/xxx");
}else{
mraid.open("https://apps.apple.com/xxx");
}
}
[/script]

Normally, I would put that function into Hype and have a button object call the function under Hype's Actions/On Mouse Click. Like this...

function appstore(hypeDocument, element, event) {
if(navigator.userAgent.indexOf("Android") != -1){
mraid.open("https://play.google.com/store/xxx");
}else{
mraid.open("https://apps.apple.com/xxx");
}
}

but that isn't acceptable by the Publisher. I was told by them that the function has to be put at the top of the html file and I need to call the function from a button in Hype. But what would be the syntax for the Action? How can I call a function that I have to put into the final html file AFTER I export it. Even if I type in the proper syntax manually, I am not sure what that syntax actually is. :smiley:

Any help is welcome.

Just use the first code chunk in head HTML

<script>
function appstore() {
    if (navigator.userAgent.indexOf("Android") != -1) {
        mraid.open("https://play.google.com/store/xxx");
    } else {
        mraid.open("https://apps.apple.com/xxx");
    }
}
</script>

and in Hype add a button with a JS function that calls appstore()

function open_appstore(hypeDocument, element, event) {
    appstore();
}

Hi Max. That seems logical to me. But the publisher test site still gives me an error. Its as if everything in the Hype portion of the html file (deep in the giant Hype script that contains the open_appstore function) operates independently of everything outside. This seems like it should be painfully easy. It might be the if/then syntax. I'm trying it with a 'console.debug("appstore called"); ' trace to see if its hype or the publisher

edit: haha, have to learn about scrolling down :joy: :ghost:

this function in the head has global scope, so you can call it from within hype:

function anyHypeFunction(hypeDocument, element, event) {
appstore();
}

in the function a var mraid is used ... be sure it's defined somewhere otherwise it'll thow an error

Can you please share a simple file (without any art work etc.) how you are applying the script.

Its pretty involved so i can't offer a simple version. But thanks for your followup. The good news is after we tweaked the script a bit and used console debugging, I receive console results on the publishers test site when tapping the PLAY button. This demonstrates that the new function is being called. Check out the screenshot below. Also I posted the final script I used at the 'top' of the stand alone file. Its up to the publisher to explain why mraid is not available at this point. They can't blame my Hype file :wink: ...

[script type="text/javascript"]
function appstore() {
console.debug("appstore called");
if(navigator.userAgent.indexOf("Android") != -1){
console.debug("google called");
mraid.open("https://play.google.com/store/apps/xxx");
} else {
console.debug("appstore called");
mraid.open("https://apps.apple.com/us/xxx");
}
}
[/script]