0

I have a problem with the script below. I'm getting toSource is not defined error in Chrome and found out that toSource() is Firefox specific. I tried JSON.stringify() instead, for which I got undefined error.

var main_tbls = d.querySelectorAll(".bz_buglist");
var first_tbl = main_tbls[0];
first_tbl.id = "bugz_table";
var ext_script = d.createElement("script");
//ext_script.setAttribute("src", "http://www.javascriptkit.com/script/script2/tablefilter.js");
ext_script.setAttribute("type", "text/javascript");
ext_script.setAttribute("language", "javascript");
ext_script.appendChild(d.createTextNode("var TblId, SearchFlt, SlcArgs;TblId = new Array(), SlcArgs = new Array();var colValues = new Array();" +
    setFilterGrid.toSource() +
    AddGrid.toSource() ));
d.body.appendChild(ext_script);


function setFilterGrid(id)
{
    var tbl = grabEBI(id);
    var ref_row, fObj;
    if (tbl != null && tbl.nodeName.toLowerCase() == "table") {
        if (arguments.length > 1) {
            for (var i = 0; i < arguments.length; i++) {
                var argtype = typeof arguments[i];

                switch (argtype.toLowerCase()) {
                    case "number":
                        ref_row = arguments[i];
                        break;
                    case "object":
                        fObj = arguments[i];
                        break;
                } //switch

            } //for
        } //if

        ref_row == undefined ? ref_row = 2 : ref_row = (ref_row + 2);
        var ncells = getCellsNb(id, ref_row);
        tbl.tf_ncells = ncells;
        if (tbl.tf_ref_row == undefined) tbl.tf_ref_row = ref_row;
        tbl.tf_Obj = fObj;
        if (!hasGrid(id)) AddGrid(id);
    } //if tbl!=null
}
Makyen
  • 27,758
  • 11
  • 68
  • 106
user3383301
  • 1,731
  • 3
  • 15
  • 41
  • there is no inner function `toSource` defined inside `seFilterGrid` – brk Oct 01 '16 at 06:53
  • 3
    Please review [*How do I ask a good question?*](/help/how-to-ask) What is your goal? What end result do you want? What specifically about the output of `JSON.stringify` was problematic? – T.J. Crowder Oct 01 '16 at 06:53
  • @user2181397 : toSource is an inbuilt firefox plugin ! I want to use the chrome equivalent of it – user3383301 Oct 01 '16 at 06:57
  • http://stackoverflow.com/questions/171407/implementing-mozillas-tosource-method-in-internet-explorer – adeneo Oct 01 '16 at 07:07
  • 1
    It's not a plugin, it's a non-standard prototype only implemented in Gecko, that you generally shouldn't use. – adeneo Oct 01 '16 at 07:08

1 Answers1

3

While your question is not clear, it appears that you are looking for the Function.prototype.toString() method. This will work in basically all browsers.

document.body.innerHTML =  '<pre>' + setFilterGrid.toString() +'</pre>';


function setFilterGrid(id)
{
    var tbl = grabEBI(id);
    var ref_row, fObj;
    if (tbl != null && tbl.nodeName.toLowerCase() == "table") {
        if (arguments.length > 1) {
            for (var i = 0; i < arguments.length; i++) {
                var argtype = typeof arguments[i];

                switch (argtype.toLowerCase()) {
                    case "number":
                        ref_row = arguments[i];
                        break;
                    case "object":
                        fObj = arguments[i];
                        break;
                } //switch

            } //for
        } //if

        ref_row == undefined ? ref_row = 2 : ref_row = (ref_row + 2);
        var ncells = getCellsNb(id, ref_row);
        tbl.tf_ncells = ncells;
        if (tbl.tf_ref_row == undefined) tbl.tf_ref_row = ref_row;
        tbl.tf_Obj = fObj;
        if (!hasGrid(id)) AddGrid(id);
    } //if tbl!=null
}

Function.prototype.toSource(), on the other hand, is only available in Firefox. Mozilla's documentation is quite clear that it is:

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Makyen
  • 27,758
  • 11
  • 68
  • 106