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() {... ここにあなたのもの... })()) です

getDay は曜日を返すため、getDay ではなく getDate() も使用する必要があることに注意してください。

于 2009-04-08T17:04:46.060 に答える
0

document.location の代わりにwindow.location.hrefを使用することをお勧めします。

于 2009-04-08T03:19:35.453 に答える