使用 document.write 控制 javascript twitter 小部件

发布于 2024-10-21 18:50:56 字数 2668 浏览 4 评论 0原文

我正在尝试根据时间切换 twitter javascript 小部件。因此,在白天,Twitter 小部件的颜色将与晚上不同。

我使用了 Twitter 给我的代码并想出了这个代码。但我在 DW 中的“document.write”行上遇到语法错误。这是我整理的完整代码。

这是 twitter 给我的代码...

<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '@BigNotch',
  interval: 6000,
  title: 'Follow Me On Twitter',
  subject: 'BigNotch',
  width: 180,
  height: 300,
  theme: {
    shell: {
      background: '#17d1ff',
      color: '#ff8fda'
    },
    tweets: {
      background: '#ededed',
      color: '#383838',
      links: '#ff8aed'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    toptweets: true,
    behavior: 'default'
  }
}).render().start();
</script>

这是我迄今为止为实现这一目标而提出的代码。

<!-- Twitter Widget -->

<div id="isolate">   

<script src="http://widgets.twimg.com/j/2/widget.js"></script> 
</div>
<br><br /><br />


  <script type="text/JavaScript">
<!--
function changTwitter() {
var currentTime = new Date().getHours();    

 if (7 <= currentTime&&currentTime < 17) {

       document.write('<' + 'script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '@BigNotch',
  interval: 6000,
  title: 'Follow Me On Twitter',
  subject: 'BigNotch',
  width: 180,
  height: 300,
  theme: {
    shell: {
      background: '#242124',
      color: '#f0af4d'
    },
    tweets: {
      background: '#333333',
      color: '#c2c2c2',
      links: '#f7bc63'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    toptweets: true,
    behavior: 'default'
  }
}).render().start();
</' + 'script> ');   
 }

 else {
      document.write('<' + 'script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '@BigNotch',
  interval: 6000,
  title: 'Follow Me On Twitter',
  subject: 'BigNotch',
  width: 180,
  height: 300,
  theme: {
    shell: {
      background: '#17d1ff',
      color: '#ff8fda'
    },
    tweets: {
      background: '#ededed',
      color: '#383838',
      links: '#ff8aed'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    toptweets: true,
    behavior: 'default'
  }
}).render().start();
</' + 'script> ');

  }

      }


changeTwitter();
-->
</script>

我在第 88 行收到错误。“document.write('<'+'script>”

I'm trying switch the twitter javascript widgets out depending on the time. So in the day, the twitter widget will be colored differently than at night.

I used the code that twitter gave me and came up with this code. But I get a syntax error in DW on the "document.write" lines. Here is the complete code that I put together.

Here is the code that twitter gave me...

<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '@BigNotch',
  interval: 6000,
  title: 'Follow Me On Twitter',
  subject: 'BigNotch',
  width: 180,
  height: 300,
  theme: {
    shell: {
      background: '#17d1ff',
      color: '#ff8fda'
    },
    tweets: {
      background: '#ededed',
      color: '#383838',
      links: '#ff8aed'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    toptweets: true,
    behavior: 'default'
  }
}).render().start();
</script>

And here is the code i've come up w/ so far to achieve this.

<!-- Twitter Widget -->

<div id="isolate">   

<script src="http://widgets.twimg.com/j/2/widget.js"></script> 
</div>
<br><br /><br />


  <script type="text/JavaScript">
<!--
function changTwitter() {
var currentTime = new Date().getHours();    

 if (7 <= currentTime&¤tTime < 17) {

       document.write('<' + 'script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '@BigNotch',
  interval: 6000,
  title: 'Follow Me On Twitter',
  subject: 'BigNotch',
  width: 180,
  height: 300,
  theme: {
    shell: {
      background: '#242124',
      color: '#f0af4d'
    },
    tweets: {
      background: '#333333',
      color: '#c2c2c2',
      links: '#f7bc63'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    toptweets: true,
    behavior: 'default'
  }
}).render().start();
</' + 'script> ');   
 }

 else {
      document.write('<' + 'script>
new TWTR.Widget({
  version: 2,
  type: 'search',
  search: '@BigNotch',
  interval: 6000,
  title: 'Follow Me On Twitter',
  subject: 'BigNotch',
  width: 180,
  height: 300,
  theme: {
    shell: {
      background: '#17d1ff',
      color: '#ff8fda'
    },
    tweets: {
      background: '#ededed',
      color: '#383838',
      links: '#ff8aed'
    }
  },
  features: {
    scrollbar: false,
    loop: true,
    live: true,
    hashtags: true,
    timestamp: true,
    avatars: true,
    toptweets: true,
    behavior: 'default'
  }
}).render().start();
</' + 'script> ');

  }

      }


changeTwitter();
-->
</script>

I get the error on line 88. "document.write('<'+'script>"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2024-10-28 18:50:56

document.write 接受一个字符串 arg,但在您的代码中,该字符串未正确终止,请使用 document.write('<'+'script>'+"all the other code" +'');

JAVASCRIPT 不支持您发布的多行字符串。

document.write takes an string arg, but in your code, the string is not terminated correctly, use document.write('<'+'script>'+"all the other code" +'');

JAVASCRIPT does not support multi-line string like you post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文