开发者

How do I move a Javascript phrase (within the body) into the head instead

For example I have a code that drags in my twitter feed via a javascript file, I have pasted the links directly in the div I wish for it to appear however my page won't validate (obviously) but I can't figure out how to send it to appear in that div with the Javascript code hidden in the header.

Below shows the div I need the i开发者_运维技巧nformation in and the javascript files that call the information

Any help would be greatly appreciated !

<div id="twitter_update_list"><script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/hookline_sinker.json?callback=twitterCallback2&count=1"></script>
<br />FIND US AT <br /><strong><a href="http://twitter.com/#!/hookline_sinker" target="_blank">@HOOKLINE_SINKER</a></strong></div> 


The only reason that I can see for that not to validate is that the ampersands in the URI haven't been HTML encoded (i.e. as &amp;).

<script> elements are allowed as child elements of <div> elements.


If you're using the JavaScript provided by Twitter then I don't think you can.

What you're after (if I understand correctly) is an external JavaScript file that you link to in the <head> of your page, that traverses the DOM on page-load, finds a div with an ID of "twitter_update_list" and inserts the content from Twitter.

While this functionality is quite easy to code, it would have to be within the JavaScript file itself. Since you're using Twitter's JavaScript then it's up to Twitter to provide this functionality within their JavaScript.

I think you'd have to look into writing your own JavaScript file that fetched your Twitter RSS feed and parsed it on your page.

You might want to look at Remy Sharp's solution - at a brief glance it looks to do what you want: http://remysharp.com/2007/05/18/add-twitter-to-your-blog-step-by-step/


<html>
<head>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js">
</script>
</head>
<body>
<br />FIND US AT <br /><strong><a href="http://twitter.com/#!/hookline_sinker" target="_blank">@HOOKLINE_SINKER</a></strong>
<div id="twitter_update_list">Updates will go here!</div>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/hookline_sinker.json?callback=twitterCallback2&count=1"></script>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜