Skip to content Skip to sidebar Skip to footer

How To Call Function Inside Of The Function In Html?

How can I call 'stop()' at HTML? It's inside of downloadFile2(). js example function download() { var req = request({ method: 'GET', uri: url });

Solution 1:

You can make use events, Call stop function from HTML.

const events = require('events');
varEventEmitter = new events.EventEmitter();

functiondownload() {
    var req = request({
        method: 'GET',
        uri: url
    });
    var out = fs.createWriteStream(path);
    req.pipe(out);

    EventEmitter.on("stop",function(){
        req.pause();
    })

    req.on('response', function (data) {
    });
    req.on('data', function (chunk) {
        stop();//I want to execute this method at html .
    });
}
functionstop() {
    EventEmitter.emit("stop");
}

But make sure download function gets called before stop function.

Solution 2:

you can call function inside of another by this

function download() {
  var req = request({
    method: 'GET',
    uri: url
  });
  varout = fs.createWriteStream(path);
  req.pipe(out);

  this.stop = function stop(){
   req.pause();
  }

  req.on('response', function(data) {
  });
  req.on('data', function(chunk) {
    stop();//I want to execute this method at html .
  });
}

Then call the child function by this

<td><aclass="checkBtn"onclick="(new download()).stop();"value="ACTION">stop~!!!</a></td>

Post a Comment for "How To Call Function Inside Of The Function In Html?"