jQuery.load不与文件撰写执行的JavaScript [英] jQuery.load doesn't execute javascript with document.write

查看:166
本文介绍了jQuery.load不与文件撰写执行的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用jQuery.Load加载广告调用,有一个文件撰写,而由于某种原因,它不能够,或在Firefox ATLEAST,重新加载与整个广告的页面。

I am trying to use jQuery.Load to load an ad call that has a document.write, and for some reason its not able to, or in firefox atleast, reloads the page with the entire ad.

这里是code的简化版本。

Here is the simplified version of the code.

DynamicLoad.html

DynamicLoad.html

<html>
<head>
<script src="http://www.prweekus.com/js/scripts.js?3729212881" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Load of Script</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
   google.load("jquery", "1.3.2");
</script>
<script type="text/javascript">
   $(document).ready(function(){
    $("#myButton").click(function() {
        $("#myDiv").load("source.html");
    });
   });
</script>
</head>
<body>
<button id="myButton">Click Me</button>
<div id="myDiv"></div>

<div id="slideAdUnit"></div>

</body>
</html>

Source.html

Source.html

<script language="javascript" type="text/javascript">
  document.write('<script language="javascript" type="text/javascript"><\/script>');
</script>
test

一旦你点击在FF按钮,浏览器只是等待的东西加载。有什么想法吗 ?

Once you click the button in FF the browser just waits for something to load. Any thoughts ?

最后,我将传递指向我们的广告服务器中的文件撰写一个src元素。

Eventually I would be passing a src element in the document.write which points to our ad server.

感谢您的帮助。

推荐答案

您无法使用文件撰写

You can't use document.write after the page has finished loading: it will replace the contents of the page if you do.

要动态加载使用jQuery脚本最简单的方法是:

The easiest way to load a script dynamically with jQuery is:

$.getScript( url );

另一种方法是创建一个新的&LT;脚本&GT; 元素,并将其添加到文档

Another way is to create a new <script> element and add it to the document.

这篇关于jQuery.load不与文件撰写执行的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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