我有一个外部Javascript文件,我已链接到我的html文件。定位工作正常,直到我尝试使用外部JavaScript文件。当我链接到头部时,RSS源就会进入我的页面顶部。我可以把链接放在我的html文件的任何地方,或者它必须在头上。我希望RSS源位于“新闻源”标识下。我也遗漏了我的页面的一些信息,因为我只需要显示div和css。链接到外部JavaScript文件时定位RSS提要
这里是我的html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>GamerZone</title>
<link type="text/css" rel="stylesheet" href="index.css" />
<link rel="shortcut icon" type="icon/ico" href="images/icon.ico" />
<script type="text/javascript" src="rss-feed.js"></script>
</head>
<body>
<div id="allcontent">
<div id="banner">
<a target="_self" href="index.html" title="">
<img src="images/banner.jpg" border="0" alt="GamerZone Banner">
</a>
</div>
<div class="container">
<ul class="nav">
<li class="nav-home">
<a href="index.html">Home</a>
</li>
<li class="nav-games">
<a href="games.html">Games</a>
</li>
<li class="nav-chat">
<a href="chat.html">Chat</a>
</li>
<li class="nav-suggestions">
<a href="suggestions.html">Suggestions</a>
</li>
</ul>
</div>
<div id="newsfeed">
//RSS feed goes here
</div>
<div id="footer">
</div>
</div>
</body>
</html>
这里是我的CSS代码:
#allcontent {
width: 1000px;
padding-top: 5px;
padding-bottom: 5px;
background-color: ;
margin-left: auto;
margin-right: auto;
}
#poll {
background-color: white;
float: left;
padding: 0px 5px 5px 5px;
margin: 15px 10px 10px 22px;
font-family: Tahoma;
}
#newsfeed {
padding: 15px;
margin: 0px 10px 10px 10px;
}
这里是我的Javascript代码:
<!--
rssfeed_url = new Array();
rssfeed_url[0]="http://news.yahoo.com/rss/gaming";
rssfeed_frame_width="500";
rssfeed_frame_height="720";
rssfeed_scroll="on";
rssfeed_scroll_step="6";
rssfeed_scroll_bar="on";
rssfeed_target="_blank";
rssfeed_font_size="14";
rssfeed_font_face="";
rssfeed_border="on";
rssfeed_css_url="http://example.com/newsfeed.css";
rssfeed_title="on";
rssfeed_title_name="";
rssfeed_title_bgcolor="#3366ff";
rssfeed_title_color="#fff";
rssfeed_title_bgimage="http://";
rssfeed_footer="off";
rssfeed_footer_name="rss feed";
rssfeed_footer_bgcolor="#fff";
rssfeed_footer_color="#333";
rssfeed_footer_bgimage="http://";
rssfeed_item_title_length="50";
rssfeed_item_title_color="#666";
rssfeed_item_bgcolor="#fff";
rssfeed_item_bgimage="http://";
rssfeed_item_border_bottom="on";
rssfeed_item_source_icon="off";
rssfeed_item_date="off";
rssfeed_item_description="on";
rssfeed_item_description_length="120";
rssfeed_item_description_color="#666";
rssfeed_item_description_link_color="#333";
rssfeed_item_description_tag="off";
rssfeed_no_items="0";
rssfeed_cache = "7872565d53aadc6c14b4ab1bb3f79bdb";
//-->
(function(){
var a=window;
var b="";
for(i=0;i<a.rssfeed_url.length;i++) {
b=b+"rssfeed[url]["+i+"]="+encodeURIComponent(a.rssfeed_url[i])+"&"
}
var c="http://feed.surfing-waves.com/php/rssfeed.php"+"?"+b+"rssfeed[type]="+(a.rssfeed_type?a.rssfeed_type:"")+"&rssfeed[frame_width]="+a.rssfeed_frame_width+"&rssfeed[frame_height]="+a.rssfeed_frame_height+"&rssfeed[scroll]="+(a.rssfeed_scroll?a.rssfeed_scroll:"")+"&rssfeed[scroll_step]="+(a.rssfeed_scroll_step?a.rssfeed_scroll_step:"")+"&rssfeed[scroll_bar]="+(a.rssfeed_scroll_bar?a.rssfeed_scroll_bar:"")+"&rssfeed[target]="+(a.rssfeed_target?a.rssfeed_target:"")+"&rssfeed[font_size]="+(a.rssfeed_font_size?a.rssfeed_font_size:"")+"&rssfeed[font_face]="+(a.rssfeed_font_face?a.rssfeed_font_face:"")+"&rssfeed[border]="+(a.rssfeed_border?a.rssfeed_border:"")+"&rssfeed[css_url]="+(a.rssfeed_css_url?encodeURIComponent(a.rssfeed_css_url):"")+"&rssfeed[title]="+(a.rssfeed_title?a.rssfeed_title:"")+"&rssfeed[title_name]="+(a.rssfeed_title_name?a.rssfeed_title_name:"")+"&rssfeed[title_bgcolor]="+(a.rssfeed_title_bgcolor?encodeURIComponent(a.rssfeed_title_bgcolor):"")+"&rssfeed[title_color]="+(a.rssfeed_title_color?encodeURIComponent(a.rssfeed_title_color):"")+"&rssfeed[title_bgimage]="+(a.rssfeed_title_bgimage?encodeURIComponent(a.rssfeed_title_bgimage):"")+"&rssfeed[footer]="+(a.rssfeed_footer?a.rssfeed_footer:"")+"&rssfeed[footer_name]="+(a.rssfeed_footer_name?a.rssfeed_footer_name:"")+"&rssfeed[footer_bgcolor]="+(a.rssfeed_footer_bgcolor?encodeURIComponent(a.rssfeed_footer_bgcolor):"")+"&rssfeed[footer_color]="+(a.rssfeed_footer_color?encodeURIComponent(a.rssfeed_footer_color):"")+"&rssfeed[footer_bgimage]="+(a.rssfeed_footer_bgimage?encodeURIComponent(a.rssfeed_footer_bgimage):"")+"&rssfeed[item_bgcolor]="+(a.rssfeed_item_bgcolor?encodeURIComponent(a.rssfeed_item_bgcolor):"")+"&rssfeed[item_bgimage]="+(a.rssfeed_item_bgimage?encodeURIComponent(a.rssfeed_item_bgimage):"")+"&rssfeed[item_title_length]="+(a.rssfeed_item_title_length?a.rssfeed_item_title_length:"")+"&rssfeed[item_title_color]="+(a.rssfeed_item_title_color?encodeURIComponent(a.rssfeed_item_title_color):"")+"&rssfeed[item_border_bottom]="+(a.rssfeed_item_border_bottom?a.rssfeed_item_border_bottom:"")+"&rssfeed[item_source_icon]="+(a.rssfeed_item_source_icon?a.rssfeed_item_source_icon:"")+"&rssfeed[item_date]="+(a.rssfeed_item_date?a.rssfeed_item_date:"")+"&rssfeed[item_description]="+(a.rssfeed_item_description?a.rssfeed_item_description:"")+"&rssfeed[item_description_length]="+(a.rssfeed_item_description_length?a.rssfeed_item_description_length:"")+"&rssfeed[item_description_color]="+(a.rssfeed_item_description_color?encodeURIComponent(a.rssfeed_item_description_color):"")+"&rssfeed[item_description_link_color]="+(a.rssfeed_item_description_link_color?encodeURIComponent(a.rssfeed_item_description_link_color):"")+"&rssfeed[item_description_tag]="+(a.rssfeed_item_description_tag?a.rssfeed_item_description_tag:"")+"&rssfeed[no_items]="+(a.rssfeed_no_items?a.rssfeed_no_items:"")+"&rssfeed[cache]="+(a.rssfeed_cache?a.rssfeed_cache:"");
if(a.rssfeed_border!="off"&&!a.rssfeed_css_url){}
document.write('<iframe name="rssfeed_frame" width="'+a.rssfeed_frame_width+'" height="'+a.rssfeed_frame_height+'" frameborder="0" src="'+c+'" marginwidth="0" marginheight="0" vspace="0" hspace="0" scrolling="no" ALLOWTRANSPARENCY="true"></iframe>')
})()
如果需要任何额外的信息,请拒绝前询问我的问题。 另外,为了将来的参考,是否有一种方法可以正确格式化一切,而不会造成一百万次空间?如果这被视为一个额外的问题,不允许然后忽略。谢谢。
这是一个愚蠢的问题,我猜。唯一的另一个问题是,我的科学Sci教授说,JavaScript文件的链接应该在头上。虽然,如果你的方式很好,那么我只会使用它。 – TheUnCola 2013-04-05 16:06:21
当浏览器解析一个JavaScript文件时,它基本上只是将它插入到html中,就好像它是一个脚本块在它所链接的位置。如果该JavaScript文件正在做的东西在头部没有意义,那么该文件不应该从那里链接。 document.write()在运行代码的文档中输出html,如果它添加了应该在主体中的代码,那么脚本应该在主体中。 – Racheet 2013-04-05 16:25:58
感谢您的帮助,你们俩。 – TheUnCola 2013-04-05 16:33:15