SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Including url and todays date in a bookmark

    Hi

    I'm a total novice with scripts but I've managed to get halfway with something.

    I want to create a bookmark that grabs the current url and adds the date to the url in the format:

    http://url.com/nocache=ddmmyyyy

    I've got so far:

    javascript:location.href=(location.href)+'/nocache=';

    But I can't work out how to add the date to the end, is it possible?

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For this you can easily achieve it by making a custom date in javascript:

    Code:
    function bookmark(){
    
             var
                       newDate = new Date(),
                       day = newDate.getDate(),
                       month = newDate.getMonth(),
                       year = newDate.getYear();
    
             return day + "" + (month+1) + "" + year; 
    }
    HTML Code:
    <a href="javascript: window.external.AddFavorite(location.href + 'nocache=' + bookmark(), 'Page Title');">Bookmark this page</a>
    I should note that this has only been tested in IE8. I'm not sure if it works in other browsers as I don't currently have access to anything else (oh, the horror).
    The only part I'm concerned about failing in another browser is the 'window.external.AddFavorite' part.
    Last edited by sd_javascript; May 19, 2011 at 05:44. Reason: Adding some info...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •