Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 733113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:13:10+00:00 2026-05-14T07:13:10+00:00

I’ve got a nice piece of javascript <script type=text/javascript><!– var d = new Date();

  • 0

I’ve got a nice piece of javascript

<script type="text/javascript"><!--
var d = new Date();
d.setTime(d.getTime()-86400*1000);
window.location = "https://mail.google.com/mail/?shva=1#search/in%3Ainbox+before%3A"+(d.getYear()+1900)+"%2F"+(d.getMonth()+1)+"%2F"+d.getDate();
//-->
</script>

That works entirely satisfactorily when I visit the .html file that i store the javascript in.

However, I’d like to get the same effect from using a bookmarklet – however, when I put

javascript:var%20d%20=%20new%20Date();%20d.setTime(d.getTime()-86400*1000);%20window.location%20=%20"https://mail.google.com/mail/?shva=1#search/in%3Ainbox+before%3A"+(d.getYear()+1900)+"%2F"+(d.getMonth()+1)+"%2F"+d.getDate();

into my bookmark I’m taken to re:2010/4/20 rather than
re%3A2010%2F4%2F20

I’m assuming that there’s some problem with the escape characters in either the bookmarking system or javascript but I’m not getting anywhere – anyone care to lend a hand?

Joe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:13:11+00:00Added an answer on May 14, 2026 at 7:13 am

    I would try wrapping that whole chunk of code in a function, so that your bookmarklet (un-escaped) looks like this:

    (function() {
        var d = new Date();
        d.setTime(d.getTime()-86400*1000);
        window.location = 
          "https://mail.google.com/mail/?shva=1#search/in%3Ainbox+before%3A" + 
          d.getFullYear()+"%2F"+(d.getMonth()+1) + "%2F" + d.getDate();
    })();
    

    But that’s just me. More important, those escaped characters would need to be double-escaped when you’re turning it into bookmarklet form.

    javascript:%28function%28%29%20%7B%0A%20%20%20%20%20%20%20%20var%20d%20%3D%20new%20Date%28%29%3B%0A%20%20%20%20%20%20%20%20d.setTime%28d.getTime%28%29-86400*1000%29%3B%0A%20%20%20%20%20%20%20%20window.location%20%3D%20%0A%20%20%20%20%20%20%20%20%20%20%22https%3A//mail.google.com/mail/%3Fshva%3D1%23search/in%253Ainbox+before%253A%22%20+%20%0A%20%20%20%20%20%20%20%20%20%20d.getFullYear%28%29+%22%252F%22+%28d.getMonth%28%29+1%29%20+%20%22%252F%22%20+%20d.getDate%28%29%3B%0A%20%20%20%20%7D%29%28%29%3B
    

    Also there’s a function on Date instances called “getFullYear”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd suggest using positions = ((n, n + hits_per_page -… May 14, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer You may check out prawn too. Tutorial can be found… May 14, 2026 at 8:24 pm
  • Editorial Team
    Editorial Team added an answer Interesting question. Personally, I try not to store complex objects… May 14, 2026 at 8:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.