Take the 2-minute tour ×

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:


            <!--Load the AJAX API-->
            <script type="text/javascript" src="../stringformat.js"></script>
            <script type="text/javascript">


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


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


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

share|improve this question
Are you sure that ../stringformat.js is loaded? –  Explosion Pills Apr 1 '13 at 18:48
And what does stringformat.js do? If it doesn't add format to String.prototype, I wouldn't expect it to work. –  bfavaretto Apr 1 '13 at 18:49
@Explosion Pills: I'm not 100% sure, but the code worked outside the hudson –  user1948847 Apr 1 '13 at 18:56
Try putting the content of stringformat.js inline in the html file –  Rodrigo Assis Apr 1 '13 at 19:00
Can you check your web server log to see if ../stringformat.js was requested and served? Also, this might be useful: stackoverflow.com/questions/8618464/… –  Andrew Morton Apr 1 '13 at 19:01
add comment

1 Answer

try code:

<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(){
<input type="button" name="btnTest" id="btnTest" value="Test string format" onclick="show();" /> 
share|improve this answer
add comment

Your Answer


