1

如果我将其加载到新选项卡(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;

有什么帮助吗?

谢谢 :)

更新:

当我从这个答案中删除多余的空格并将必要的空格转换为“%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;})())

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

4

2 回答 2

3

你想要的是看起来像这样的东西:

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 返回星期几!

于 2009-04-08T17:04:46.060 回答
0

最好使用window.location.href 而不是document.location

于 2009-04-08T03:19:35.453 回答