运行用ajax加载的脚本标记 [英] Run script tags loaded with ajax
问题描述
假设您有一个简单的ajax请求,例如 $(#container)。load('/ url #content' );
。加载的DOM将类似于
Say you have a simple ajax request like $("#container").load('/url #content');
. The loaded DOM will be something like
<a>email</a>
<script>/* some script */</script>
我该怎么做才能让脚本标签的内容执行?
What can I do to get the contents of the script tags to execute?
Cloudflare通过用 [email protected] <替换文本自动保护DOM中的电子邮件地址/ code>并包括一个解开它的脚本。但是,可以异步加载内容,并且不会执行解析的脚本。我可以关闭电子邮件保护功能(我想),但我想知道是否还有另一种解决方法。
Cloudflare automatically protects email addresses in the DOM by replacing the text with [email protected]
and including a script that unravels it. However, the contents can be loaded asynchronously and the script that does the unraveling won't be executed. I could just turn off the email protection feature (I think) but I'm wondering if there's another way around this.
在 http://aysites.com/what 上查看实际操作 - 点击联系
See it in action at http://aysites.com/what -- click "Contact"
推荐答案
有一个纯js函数可以调用JavaScript编译器。它是 eval
。您需要使用它。
There is a pure js function which invokes the JavaScript compiler. It's eval
. You need to use it.
示例:
jQuery.globalEval("var newVar = true;")
on jQuery.com
或
eval("x=10;y=20;document.write(x*y)");
document.write("<br />" + eval("2+2"));
document.write("<br />" + eval(x+17));
on w3schools
这篇关于运行用ajax加载的脚本标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!