通过的UpdatePanel异步回发后重新加载外部JavaScript [英] Reload external javascript after asynchronous postback via UpdatePanel

查看:201
本文介绍了通过的UpdatePanel异步回发后重新加载外部JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部JavaScript我的网页,例如是这样的:

I have an external javascript on my page, e.g. something like:

<script src="http://foo.com/script.js" type="text/javascript"></script>

和一个UpdatePanel的地方。该脚本写一些内容,而做到这一点从js文件的匿名javascript函数内。即有像这样的脚本:

and an UpdatePanel somewhere. The script writes some content, and does this from within an anonymous javascript function in the js file. I.e., there is something like this in the script:

(function(){document.write('content');})();

每当在UpdatePanel通过异步回发更新,一切剧本做了(或我的网页上任何JavaScript,为此事)是由百废待兴。
对于正常的JavaScript,我只想用:

Whenever the UpdatePanel is updated through asynchronous postback, everything the script did (or any javascript on my page, for that matter) is made undone. For normal javascript, I would just use:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(myFunction)

重做这一切,但因为脚本源文件中的函数是匿名的,并呼吁定义,我SOL!任何想法?

to redo all that, but since the function in the script source file is anonymous and called upon definition, I'm SOL! Any ideas?

请注意:外部JS源是从另一个域,它的内容是在我的掌握

Note: the external js source is from another domain and its content is out of my control.

推荐答案

确定,解决方案(肮脏丑陋的黑客攻击,如果你preFER),我想出了:

Ok, the "solution" ("dirty ugly hack", if you prefer) I came up with:

而不是直接加载js文件,我通过一个包装,读取该文件,包装是把匿名函数在全球阵列结果在自定义JavaScript加载它,并在负荷和之后的每个电话中说阵列中的所有功能异步回送。

Instead of loading the js file directly, I load it via a wrapper that reads the file, wraps the result in custom javascript that puts the anonymous function in a global array, and call all functions in said array upon load and after each asynchronous postback.

请不要在任何选美进入这个解决方案。

Please don't enter this solutions in any beauty pageants.

这篇关于通过的UpdatePanel异步回发后重新加载外部JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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