【问题标题】:gmail javascript bookmarkletgmail javascript小书签
【发布时间】:2009-04-08 00:19:27
【问题描述】:

如果我将它加载到新标签 (FF3) 中,它会起作用。如果我将它加载到当前选项卡中,它只会打印 url。

我认为这实际上是在现有的 gmail 标签中加载它的问题。比如说,制作小书签,单击一次,然后再次单击它。这似乎是重现问题的方法。

知道是什么原因造成的吗?我可以想到一些解决方法,但我很好奇它是如何工作的。

javascript:var%20t=new%20Date(),y=t.getFullYear(),m=t.getMonth()+1,d=t.getDate();document.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d

/* same code split up for readability */
javascript:
  var t = new Date(),
      y = t.getFullYear(),
      m = t.getMonth()+1,
   /* d = t.getDay(); I actually have this correct above, but not here.. oops */
      d = t.getDate(); 
  document.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;

有什么帮助吗?

谢谢:)

更新:

当我从this 答案中删除多余的空格并将必要的空格转换为“%20”(url 编码)时,它什么都不做:

 /* this works. I was missing the final ")" altCognito wrote */
 javascript:void((function(){var%20t=%20new%20Date(),y=t.getFullYear(),m=t.getMonth()+1,d=t.getDate();window.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;})())

我还尝试了一些分号摆弄和其他一般语法检查,但我不确定我在寻找什么。它既不能用作书签,也不能直接粘贴到地址栏中(无论如何对我来说)。

【问题讨论】:

  • 当我在当前选项卡上加载它时,这似乎可以在我的浏览器 (FF3) 上运行——尽管我没有登录到 gmail ATM。
  • WFM。登录与否;新标签或当前标签;无论如何,我建议使用快速拨号。
  • 尝试连续加载两次(登录时)。那你怎么办?

标签: javascript firefox gmail bookmarklet


【解决方案1】:

你想要的是这样的东西:

javascript:void(
    (function() {
    var t = new Date(),
          y = t.getFullYear(),
          m = t.getMonth()+1,
          d = t.getDate();
      window.location.href="http://mail.google.com/mail/#search/is%3Aunread+after%3A"+y+"-"+m+"-"+d;
    })()
)

关键是 void((function() {... Your stuff here ... })())

注意,您还想使用 getDate(),而不是 getDay,因为 getDay 返回星期几!

【讨论】:

  • 这个变化到底是什么意思?为什么要调用 void 和匿名函数?
【解决方案2】:

【讨论】:

  • 我不认为是这样。我用新信息更新了问题。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-18
  • 1970-01-01
相关资源
最近更新 更多