将javascript注入javascript函数 [英] Inject javascript into a javascript function

查看:169
本文介绍了将javascript注入javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,我需要将一些javascript注入另一个javascript函数。我正在使用一个锁定的框架,因此无法更改现有功能。

I've got a weird question in that I need to inject some javascript into another javascript function. I am using a framework which is locked so I can not change the existing function.

我所拥有的就是这样的东西

What I've got is something like this



... ***

...***

我可以操纵***(上方),但不能更改doSomething函数...相反,我需要以某种方式在doSomething代码的末尾插入几行代码。

I can manipulate the ***(above) however I can not change the doSomething function... Instead I need to somehow inject a few lines of code into the end of the doSomething code.

我需要这样做的原因是自定义框架调用doSomething(),这导致我需要提取的服务器返回了一个ID。此ID仅在doSomething函数内部引用,因此除非将代码注入该函数(除非我错过了什么),否则我无法捕获它。

The reason I need to do this is that the custom framework calls doSomething() and this results in an ID being returned from the server that I need to extract. This ID is only referenced inside the doSomething function so I can not catch it unless I inject code to that function (unless I've missed something).

有没有办法做到这一点?

Is there a way to do this?

推荐答案

别名

var oldDoSomething = doSomething;
doSomething = function() {
  // Do what you need to do.
  return oldDoSomething.apply(oldDoSomething, arguments);
}

这篇关于将javascript注入javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆