简体   繁体   English

IE问题:将不会执行作为AJAX内容的一部分加载的javascript

[英]IE Problem: Won't execute javascript loaded as part of AJAX content

I'm loading AJAX content that contains a javascript function inside the AJAX content. 我正在加载AJAX内容中包含javascript函数的AJAX内容。 I'm using the jQuery .load function and calling done() on completion. 我正在使用jQuery .load函数,并在完成时调用done()。

$('#content').load(a, done);

function done()
{
    if(pagejs() == 'function')
    {
        pagejs();
    }
}

I'm not able to get the function to execute in IE 9 but in FF and Chrome the script is executed fine. 我无法在IE 9中执行该功能,但在FF和Chrome中,脚本可以正常执行。 In IE, I'm getting a SCRIPT5007: Object expected error on the if(pagejs() == 'function') line. 在IE中,我得到了SCRIPT5007: if(pagejs() == 'function')行上的对象预期错误。

I added the compatibility meta tag: <meta http-equiv="X-UA-Compatible" content="IE=8" /> still with no success. 我添加了兼容性元标记: <meta http-equiv="X-UA-Compatible" content="IE=8" />仍然没有成功。

Here is a sample of the AJAX content: 这是AJAX内容的样本:

<div id="about"><h1>About This Website</h1>

<script type="text/javascript">
function pagejs(){alert('content was loaded from dynamic script');}
</script>

<p>This is test AJAX content</p>

In IE, the pagejs(); 在IE中, pagejs(); is undefined. 未定义。 Can someone please tell me how I can get IE to recognize this script? 有人可以告诉我如何让IE识别此脚本吗? Thank you. 谢谢。

pagejs() == 'function'

That executes pagejs and compares it's return value to the string function . 执行pagejs并将其返回值与string function进行比较。

You want typeof pagejs === 'function' 您需要typeof pagejs === 'function'

尝试if(typeof(pagejs) == 'function')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM