/    Sign up×
Community /Pin to ProfileBookmark

Calling a Function

This seems like it should be a simple thing, but it’s turning out to be frustrating. I’m a complete newb to javascript. But the principle should be the same as other scripts. I have a function in ‘javaFunc.js’, and this file is in the same directory as the index.html file that’s calling it. But it’s not working. Here’s my code:

html file:

[code=php]
<HTML>
<HEAD>
<TITLE> TEST PIC </TITLE>
<SCRIPT language=”JavaScript” SRC=”javaFunc.js”></SCRIPT>
</HEAD>
</HTML>
<BODY>
<SCRIPT language=”JavaScript”>
check_plugin();
</SCRIPT>

</BODY>
</HTML>
[/code]

and the function in the javaFunc.js file is this:

[code=php]
function check_plugin() {
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes[“application/x-shockwave-flash”]) ? navigator.mimeTypes[“application/x-shockwave-flash”].enabledPlugin : 0;
document.write(‘plugin’);

if (plugin) {
var words = navigator.plugins[“Shockwave Flash”].description.split(” “);
for (var i = 0; i < words.length; ++i)
{
if (isNaN(parseInt(words[i])))
continue;
var MM_PluginVersion = words[i];
}
var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf(“MSIE”)>=0
&& (navigator.appVersion.indexOf(“Win”) != -1)) {
document.write(‘<scr’ + ‘ipt language=VBScript> n’); //FS hide this from IE4.5 Mac by splitting the tag
document.write(‘on error resume next n’);
document.write(‘MM_FlashCanPlay = ( IsObject(CreateObject(“ShockwaveFlash.ShockwaveFlash.” & MM_contentVersion)))n’);
document.write(‘</scr’ + ‘ipt> n’);
}
if (MM_FlashCanPlay) {
document.write(‘//PUT YOUR FLASH/SWF HTML SOURCE HERE’);
}
else {
document.write(‘Sorry, but you need the flash plugin to view this’);
}
}
[/code]

This doesn’t do anything but print out a few things (cause i’m still working on it, obviously) but it works fine if I put the function in the html page itself, instead of trying to call it from an external file. Before you ask, the file is there. Is there something I’m missing? For my own reasons, I’d rather have it in an external file, and not on the html page itself.

Thanks for any help,
Jaelan

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@JPnycDec 06.2004 — <script type="text/javascript" src="javaFunc.js"></script>


<body onload="check_plugin();">
Copy linkTweet thisAlerts:
@JaelanauthorDec 06.2004 — thanks for your quick reply...but that still didn't work ?

Jaelan
Copy linkTweet thisAlerts:
@russellDec 06.2004 — is there any other JS code in javaFunc.js that may have errors in it?

try something simple -- 1st line of check_plugin() put in an alert("got here");

does the alert show up?

if not, create a new function in the external js with nothing but an alert and try calling that. does that work?
Copy linkTweet thisAlerts:
@JaelanauthorDec 06.2004 — and...no, that didn't work either ? I might just have to give in and leave it in the html file

the alert doesn't work in either place (old function or new function)

Jaelan
Copy linkTweet thisAlerts:
@JPnycDec 06.2004 — If it doesn't work, you're doing something wrong. My script tags were in place of what you had there, not in addition to. And are you calling the functions from somewhere as I indicated?
Copy linkTweet thisAlerts:
@russellDec 06.2004 — is there other code in the external file? one syntax error anywhere can make it not work. Sure you spelled the file name right? Try creating a new external file with nothing in it but one function that just has an alert in it. what happens then?
Copy linkTweet thisAlerts:
@JaelanauthorDec 06.2004 — I figure I am doing something wrong, it's what i'm doing wrong that's bugging me...This was what I had as my html file when I tested your changes:
[code=php]<HTML>
<HEAD>
<TITLE> TEST PIC </TITLE>
<SCRIPT type="text/javascript" SRC="javaFunc.js"></SCRIPT>
</HEAD>
</HTML>
<BODY onLoad="check_plugin();">

</BODY>
</HTML>
[/code]
Copy linkTweet thisAlerts:
@JPnycDec 06.2004 — Then there's a syntax error in your function. Make a simple alert in a new .js file, put the name in the src in place of what's there, and call it onload of the body tag.
Copy linkTweet thisAlerts:
@JaelanauthorDec 06.2004 — Russell,

Well, I don't know what was wrong w/ the old file, but that seemed to work. So we'll see if the real function works now

Thanks,

Jaelan
Copy linkTweet thisAlerts:
@JaelanauthorDec 06.2004 — Thanks all for your help! I got it to work by creating a new file ( I had copied the old file from another folder, so it was probably a permissions issue) However, I copied it from a folder that should have had the same permissions as the new folder...but whatever, it matters not


Thanks again,

Jaelan
×

Success!

Help @Jaelan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...