1

I'm using HTML publisher in hope to have a html page with some javascript codes running on hudson. The HTML code is like this:

<html>
    <head>

            <!--Load the AJAX API-->
            <script type="text/javascript" src="https://www.google.com/jsapi"></script>
            <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
            <script type="text/javascript" src="../stringformat.js"></script>
            <script type="text/javascript">

            ......

            sql=String.format("/.csv? select from table where exchange=`ABC......")

            </script>
    </head>

However, after a successful build, my html page doesn't show what it suppose to, and as I check the error console, it says

Error: TypeError: String.format is not a function

I have put my stringformat.js into the top folder, as the HTML publisher doesn't seem to allow the file to contain anything other than HTML files.

Can anyone tell me why the String.format is not loaded properly? Thanks!

PS: stringformat.js is the file i got from

http://www.masterdata.se/r/string_format_for_javascript/

The code should be working properly as this piece of code works outside the hudson

user1948847
  • 955
  • 1
  • 12
  • 27

1 Answers1

-2

try code:

<html>
<head>
<title>String format javascript</title>
<script type="text/javascript">
    String.format = function() {
    var s = arguments[0];
    for (var i = 0; i < arguments.length - 1; i++) {
    var reg = new RegExp("\\{" + i + "\\}", "gm");
    s = s.replace(reg, arguments[i + 1]);
    }
    return s;
    }
var _myString = String.format("hi {0}, i'am {1}","everybody", "stackoverflower");
function show(){
alert(_myString);
}
</script>
</head>
<body>
<input type="button" name="btnTest" id="btnTest" value="Test string format" onclick="show();" /> 
</body>
</html>
sondt
  • 1
  • 1