1

I implemented a Javascript namespacing solution based on this answer to another stack overflow question: How do I declare a namespace in JavaScript?

Let's call this isigma-ns.js:

var ISIGMA = {
  messages: {
    noValidId: "No valid ID found",
    reason: "Reason",
    // etc...
  },

  language: "ca",
  SIGN: 2,
  PAUSE: 400,
  params: {},

  init: function(params) {
    // etc...
  },

  delay: function(callback) {
    // etc...
  },

  // etc...

  signURL: function(cert, url) {
    // etc... 
  }
};

I include this script in my page, plus other stuff:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head>
    <title>Isigma Signature Widget</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>

    <!-- Required javascript and styles for isigma widget-->
    <script type="text/javascript" src="/isme/media/signwidget/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="/isme/media/signwidget/isigma-ns.js"></script>
    <script type="text/javascript">
    $(function(){
        $("#applet").isigmaSignatureApplet({
            purpose: ISIGMA.SIGN,
            url: the_url,
            language: 'es'
        });
    });                                       
    </script>

...etc...

It works fine in Firefox, IE8, Chrome, Opera... but fails in IE7 with the message "ISIGMA is not defined" - referring to the line where I make a reference to ISIGMA.SIGN.

Any hints about what can be wrong here? Is there anything wrong with IE7 processing order of Javascript files? Any other guess?


Note: for a full reference, the whole thing is running in http://app.portasigma.com/isme/signwidget/iframe/ and the namespace JS file is really named http://app.portasigma.com/isme/media/signwidget/jquery-isigmaWidget.js

Community
  • 1
  • 1
Carles Barrobés
  • 11,608
  • 5
  • 46
  • 60

3 Answers3

4

It is the comma after "Reason". See: http://jsbin.com/upiba5/2/edit Edit: on your live site, the extra comma I see is after:

documentLockedByAnother: "This document is currently locked by another user, try again later",

  var ISIGMA = {
  messages: {
    noValidId: "No valid ID found",
    reason: "Reason"
    // etc...
  },

  language: "ca",
  SIGN: 2,
  PAUSE: 400,
  params: {},

  init: function(params) {
    // etc...
  },

  delay: function(callback) {
    // etc...
  },

  // etc...

  signURL: function(cert, url) {
    // etc... 
  }
};
offner
  • 659
  • 3
  • 12
2

You need to remove the last comma after all the properties/methods you have defined.

older versions of IE choked on this.

var ISIGMA = {
  messages: {
    noValidId: "No valid ID found",
    reason: "Reason",
    // etc...
  },

  language: "ca",
  SIGN: 2,
  PAUSE: 400,
  params: {},

  init: function(params) {
    // etc...
  },

  delay: function(callback) {
    // etc...
  },<====-- if this is the LAST property/method, you need to omit the comma.

  // etc...
};

Update: another potential issue can arise from "self-closing" script tags. Be sure you have no external scripts referenced like this:

<script src="..."/><!--prone to parsing bugs/errors-->

vs.

<script src="..."></script><!--correct-->
scunliffe
  • 62,582
  • 25
  • 126
  • 161
  • there is no last comma in my complete file, I'll update the sample accordingly – Carles Barrobés Dec 20 '10 at 17:58
  • sure: the whole thing is running in http://app.portasigma.com/isme/signwidget/iframe/ and the namespace JS file is really named http://app.portasigma.com/isme/media/signwidget/jquery-isigmaWidget.js – Carles Barrobés Dec 20 '10 at 18:05
  • I'd recommend installing the "Microsoft IE developer toolbar" in IE7... it may reveal where the error actually is. (I don't have access to IE7 ATM) – scunliffe Dec 20 '10 at 18:21
  • Thanks, I was going to ask whether such a thing existed... I normally develop with Firefox and debug with Firebug, and have also used the developer extension to IE8, but knew no IE7 equivalent. – Carles Barrobés Dec 20 '10 at 20:51
1

You have two external scripts loading and then immediately run an inline script. Scripts can load asynchronously or even fail to load at all. It is possible for browsers to single task and complete loading one script before moving on to the next script and it is possible for them to run multiple concurrent requests and it is possible for them to wait until all external requests have completed before continuing parsing inline scripts; but you have little (if any) control over which of those options any specific browser decides to implement. I don't have IE7, so I cannot experiment to see if its action differs from IE8's. You should ensure that the 2nd script has fully loaded before running the inline script.

j5c
  • 11
  • 1