/    Sign up×
Community /Pin to ProfileBookmark

Java in Firefox Address bar

A brief introduction. I’m completely new to javascript but am hoping it will help solve this issue:

I’m trying to be able to click a bookmark and find detailed weather for the current day with one click. I know that you can use java in the address bar to go to a particular link.

e.g. (with no breaks)
javascript:location.href=’http://www.xxx.xxx/

The particular link I need, requires the current day of the year number as part of the link. Day of year can be calculated with this formula:

Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this – onejan) / 86400000)-1;
}

How can I use java to calculate the current day of the year and insert it into the url? All on one line so it can be saved as a bookmark on Firefox.

Thanks for any help on this.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Orc_ScorcherAug 18.2007 — To create a bookmarklet, write your script like you usually would, nicely formatted to improve readability. Just one caveat: for bookmarklets you [b]must[/b] end your statements with a semicolon, in normal scripts these are usually optional.

The script to go to your URL with the day of the year appended would look like this:Date.prototype.getDOY = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((this - onejan) / 86400000)-1;
}

var today = new Date;

location.href = "http://www.example.com/?day=" + today.getDOY();


Now, copy that code and paste it into the [url=http://subsimple.com/bookmarklets/jsbuilder.htm]this page[/url], prepend it with 'javascript:', press the 'Compress' button and you're done.
×

Success!

Help @Enidron28 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...