1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

building a js api, having browser problems

Discussion in 'JavaScript' started by spuntotheratboy, Aug 17, 2010.

  1. #1
    Hello,

    I'm trying to build a simple API - it's running fine in Safari and Firefox but failing in IE and Opera. In order to isolate the problem I've stripped it right back 'til all the methods are just alerting their own name. Safari and Firefox give me loads of alerts, but in Opera and IE I just get one, LMSInitialize() when the page first loads - at least I know the browser is finding the API properly.

    IE also runs LMSCommit() and LMSFinish() when you close the browser window; that's good, but not enough. Opera doesn't even do that. The trigger for all this is a Flash movie created in Adobe Captivate, and published with a whole lot of its own JS which I can't touch - it's running in an iframe, and it's the parent window which includes the API. I need to work out whether there's an issue in my code, or if it's to do with the movie or the publication settings - that side of things is out of my control.

    Here's the full code of my test version of the API. I'd really appreciate any comments!

    Thanks,
    Ben

    function SIScormAPI(){
    	this.version = '1.2';
    
    	this.LMSInitialize = LMSInitialize;
    	this.LMSFinish = LMSFinish;
    	this.LMSGetValue = LMSGetValue;
    	this.LMSSetValue = LMSSetValue;
    	this.LMSCommit = LMSCommit;
    	this.LMSGetLastError = LMSGetLastError;
    	this.LMSGetErrorString = LMSGetErrorString;
    	this.LMSGetDiagnostic = LMSGetDiagnostic;
    }
    
    function LMSInitialize(){
    
    	var alertStr1 = 'LMSInitialize() - v.'+this.version;
    	alert(alertStr1);
    }
    
    function LMSFinish(){
    
    	var alertStr2 = 'LMSFinish()';
    	alert(alertStr2);
    }
    
    function LMSGetValue(){
    
    	var alertStr3 = 'LMSGetValue()';
    	alert(alertStr3);
    }
    
    function LMSSetValue(){
    
    	var alertStr4 = 'LMSSetValue()';
    	alert(alertStr4);
    }
    
    function LMSCommit(){
    
    	var alertStr5 = 'LMSCommit()!!!!!';
    	alert(alertStr5);
    }
    
    function LMSGetLastError(){
    
    	var alertStr6 = 'LMSGetLastError()';
    	alert(alertStr6);
    }
    
    function LMSGetErrorString(){
    
    	var alertStr7 = 'LMSGetErrorString()';
    	alert(alertStr7);
    }
    
    function LMSGetDiagnostic(){
    
    	var alertStr8 = 'LMSGetDiagnostic()';
    	alert(alertStr8);
    }
    
    API = new SIScormAPI();
    Code (markup):
     
    spuntotheratboy, Aug 17, 2010 IP
  2. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Are you certain that your code is loaded and available at the point it is called by the flash in the iframe?
     
    Logic Ali, Aug 17, 2010 IP
  3. spuntotheratboy

    spuntotheratboy Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for replying.

    Yes, I'm sure, because every browser calls the LMSInitialize() method, and I get the alert. I just don't get anything subsequent to that.

    Could it be loading the class but only finding one method? I tried re-ordering the declarations within the constructor function and that didn't help. I tried putting the constructor after the function declarations since I think having the constructor first is technically an error, but that didn't make any difference either.

    Thanks,
    Ben
     
    spuntotheratboy, Aug 18, 2010 IP
  4. spuntotheratboy

    spuntotheratboy Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I've been working on this, of course, and substantially re-written the code after testing it in an on-line validator. Now it's started working in IE8 but stopped in Firefox, still working in Safari, failing in Chrome on a Mac but partly working (i.e. I'm seeing some alerts but not others) in Chrome in Windows... so that proves the error is in my code, somewhere, although it passes a fairly strict on-line validator. The 'increment' variable is just my own versioning so I can make sure that I'm not seeing results from a cached version of the API. Here's the new code in full:

    var mySIScormAlertStr = '';
    function LMSInitialize() {
    	mySIScormAlertStr = 'LMSInitialize() - ' + this.increment;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSFinish() {
    	mySIScormAlertStr = 'LMSFinish() - ' + this.increment;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSGetValue(varName) {
    	mySIScormAlertStr = 'LMSGetValue() - ' + this.increment + '\nvarName\t' + varName;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSSetValue(varName, varValue) {
    	mySIScormAlertStr = 'LMSSetValue() - ' + this.increment + '\nvarName\t' + varName + '\nvarValue\t' + varValue;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSCommit() {
    	mySIScormAlertStr = 'LMSCommit() - ' + this.increment;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSGetLastError() {
    	mySIScormAlertStr = 'LMSGetLastError() - ' + this.increment;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSGetErrorString() {
    	mySIScormAlertStr = 'LMSGetErrorString() - ' + this.increment;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function LMSGetDiagnostic() {
    	mySIScormAlertStr = 'LMSGetDiagnostic() - ' + this.increment;
    	alert(mySIScormAlertStr);
    	return true;
    }
    function SIScormAPI() {
    	this.version = '1.2';
    	this.increment = '23';
    	this.error = '0';
    	this.initialized = false;
    	this.keepValues = {};
    
    	this.LMSInitialize = LMSInitialize;
    	this.LMSFinish = LMSFinish;
    	this.LMSGetValue = LMSGetValue;
    	this.LMSSetValue = LMSSetValue;
    	this.LMSCommit = LMSCommit;
    	this.LMSGetLastError = LMSGetLastError;
    	this.LMSGetErrorString = LMSGetErrorString;
    	this.LMSGetDiagnostic = LMSGetDiagnostic;
    }
    var API = new SIScormAPI();
    Code (markup):
    Thanks to everybody who's reading this - I'd be really grateful for any kind of hint as to why it's working on some browsers and not others!

    Cheers,
    Ben
     
    spuntotheratboy, Aug 18, 2010 IP