我在通过使用 jquery load() 函数加载它来将谷歌幻灯片 ( http://www.google.com/uds/solutions/slideshow/index.html ) 加载到我的 Web 应用程序时遇到问题。
索引.html:
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<div id="moshe"></div>
<script type="text/javascript">
$(document).ready(function(){
$('#moshe').load('test.html');
});
</script>
测试.html:
<script type="text/javascript">
function load() {
var samples = "http://dlc0421.googlepages.com/gfss.rss";
var options = {
displayTime: 2000,
transistionTime: 600,
linkTarget : google.feeds.LINK_TARGET_BLANK
};
new GFslideShow(samples, "slideshow", options);
}
google.load("feeds", "1");
google.setOnLoadCallback(load);
</script>
<div id="slideshow" class="gslideshow" style="width:300px;height:300px;position:relative; border: 2px solid blue">Loading...</div>
当我执行 test.html 时,它会很好地加载幻灯片。当我尝试使用实际上调用 Jquery 的 $.load() 函数将 test.html 的内容加载到特定 div 元素中的 index.html 进行加载时,我看到画廊正在加载到该 div 上,但是当它即将显示时图像整个页面都清除了,我只有一个空白页面。
有任何想法吗 ?
不使用 jquery 的不同版本的 index.html:
<script type="text/javascript">
function makeRequest(url) {
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType('text/xml');
// See note below about this line
}
}
else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
httpRequest.open('GET', url, true);
httpRequest.send('');
}
function alertContents(httpRequest) {
if (httpRequest.readyState == 4) {
if (httpRequest.status == 200) {
document.getElementById('moshe').innerHTML=httpRequest.responseText;
} else {
alert('There was a problem with the request.');
}
}
}
makeRequest('test.html');
</script>