James Bagley

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJames Bagley
ToMe
SubjectHelp
Date6 September 2005 12:00
Hi
I wonder if you could help me.
I want to put a New or Updated sign next to a link in my webpage.
I can find a sign with New or Updated on but was wonder if there was
away that take the sign of automatically after 5 days. Is there a way of
putting a timer on it so it disappears after so long?
Not sure if you're the right person to ask.
Hope you can help
FromMe
ToJames Bagley
SubjectRe: change link after a number of days
Date6 September 2005 13:25
James,

Please use better subjects in your emails. "help" looks like spam. I was
expecting someone to start asking for help moving large money between bank
accounts for a small fee...

Anyway. Yes, you can do what you want:
<a href="foo">bar</a>
<script type="text/javascript">
var days = 5;
var createdDate = new Date('2005-8-28');
if( ( createdDate.getDate() + ( days * 86400000 ) ) > ( ( new Date() ).getTime() ) ) {
    document.write('- NEW!');
}
</script>


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJames Bagley
ToMe
SubjectRe: change link after a number of days
Date6 September 2005 14:03
Thanks so much for that. Iam really sorry for writing Help in the
subject.
What bits do I need to can I change? (Dates, days)
Thanks ever so much.
Take care 
James
FromMe
ToJames Bagley
SubjectRe: change link after a number of days
Date6 September 2005 14:31
James,

> What bits do I need to can I change? (Dates, days)

change 'days' to say how many days you want to show after the creation date.

change the date shown in createdDate (in dd Jan yyyy format)

change the text used in the document.write. you can also put HTML in there
if you want
FromJames Bagley
ToMe
SubjectNew Image Script!!!!
Date8 September 2005 11:44
Hi 
Really sorry to bother you again.
But got this script and tried it in my page and it doesn't seem to work.
Whats wrong with it?
It is suppose to: Display a "what's new" image beside new content for a
certain amount of time, then disappear automatically when the time
expires. Add a set a date, and the image will be displayed up to and
until that date, then automatically be removed. 

[Someone else's script - removed due to copyright issues]

Thanks.
James Bagley
FromMe
ToJames Bagley
SubjectRe: New Image Script!!!!
Date8 September 2005 11:58
James,

You need to actually call the function. But note, I have enough of my own
scripts to support without supporting scripts written by other people, as
stated on my contact page.

Please contact the author of the script if you want support for it.
FromJames Bagley
ToMe
SubjectRe: New Image Script!!!!
Date8 September 2005 12:03
Don't suppose you could write me a script of your own for :
Display a "what's new" image beside new content for a certain amount of
time, then disappear automatically when the time expires. Add a set a
date, and the image will be displayed up to and until that date, then
automatically be removed. 
James
FromMe
ToJames Bagley
SubjectRe: New Image Script!!!!
Date8 September 2005 18:56
James,

> Don't suppose you could write me a script

I did say I was working on one ;)

Finished it last night, just prepared all the documentation now.
http://www.howtocreate.co.uk/tutorials/jsexamples/addDateText.php

It's very easy to use, and a lot more flexible than the script you got.

You will want something like this (0,5 makes it show for the first 5 days
after publishing):

<script src="addDateText.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
  var foo = document.createElement('img');
  foo.setAttribute('src','..\/..\/news.gif');
  foo.setAttribute('alt','New');
  addDateText(0,5,'a',2,foo);
};
</script>
...
<a href="bar" title="Created 8 Sep 2005">baz</a>

There is a load of documentation in the script file as well that tells you
how to use the options.


Tarquin
FromJames Bagley
ToMe
SubjectRe: New Image Script!!!!
Date12 September 2005 09:18
HI 
Just wanted to say thank you very much for the script.
Just a few things iam not sure about:
Where do I put this:
<script src="addDateText.js" type="text/javascript"></script>
<script type="text/javascript">
...
</script>
...
<a href="bar" title="Created 8 Sep 2005">baz</a>

Not sure where to put this do I put it next to the Writing (Link) or do
I just put it in the Body Tag.

Thanks again.
James
FromMe
ToJames Bagley
SubjectRe: New Image Script!!!!
Date12 September 2005 10:03
James,

> Where do I put this:

This part (like most script libraries) goes in the <head> section of your
page. The onload handler takes care of running the script at the right time.
Just make sure you download a copy of the script library ;)

<script src="addDateText.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
   if( !document.createElement || !document.createTextNode ) { return; }
   var foo = document.createElement('img');
   foo.setAttribute('src','..\/..\/news.gif');
   foo.setAttribute('alt','New');
   addDateText(0,5,'a',2,foo);
};
</script>

Note that is you are using any other onload scripts, this could easily
conflict with them. If it causes problems for other scripts on your pages,
send me the address of a page where it is failing, and I will see if I can
work something out.

This bit is the link. it goes wherever you want the link:

<a href="bar" title="Created 8 Sep 2005">baz</a>
FromJames Bagley
ToMe
SubjectRe: New Image Script!!!!
Date12 September 2005 11:21
Thanks.
I have put it all in the corrected place now. But when I go to try it it
comes up with this errors:(See Attachment) 
James

[
Line:  352
Char:  4
Error: Object expected
Code:  0
]
FromMe
ToJames Bagley
SubjectRe: New Image Script!!!!
Date12 September 2005 12:52
James,

> I have put it all in the corrected place now. But when I go to try it it
> comes up with this errors:(See Attachment) 

Internet Explorer's error messages are completely useless to anyone. "object
expected" gives absolutelely no clue as to what the problem is. Please test
using Opera, and tell me what error messages you get in the JavaScript
console (tools - advanced - javascript console).
http://www.opera.com/download/
FromJames Bagley
ToMe
SubjectRe: New Image Script!!!!
Date12 September 2005 13:14
I have done it. This is what it said:(See Attachment)
James

[Ed. Note - you can copy/paste from the Opera 8 JavaScript console - you
do not need to send screenshots (they suck)]

[
PAGE TITLE
file://localhost/C:/....path/file.htm
Event thread: load
Error:
name: ReferenceError
message: Statement on line 4: Reference to undefined variable: addDateText
Backtrace:
  Line 4 of inline#2 script in file://localhost/C:/....path/file.htm
    addDateText(0, 5, "a", 0, "New ");
  At unknown location
    [statement source code not available]
]

[Ed. Now _that_ is a useful error message!]
FromMe
ToJames Bagley
SubjectRe: New Image Script!!!!
Date12 September 2005 13:56
James,

> I have done it. This is what it said:(See Attachment)

ok. did you download a copy of the addDateText.js script and save it into
the same directory?
http://www.howtocreate.co.uk/jslibs/addDateText.js

That is the script that actually does the work. If you have and it is still
not working, please either send me a zip package of the files you are using,
or better still, send me the address of the page on the internet where I can
see the problem for myself.
FromJames Bagley
ToMe
SubjectRe: New Image Script!!!!
Date12 September 2005 14:20
I have downloaded that and no error message comes up now. It seems to be
working ok but it looks like this in explore (see attachment) How do I
get it to show a New sign like the one below (see Attachment)
James

[Shows a broken image icon]
FromMe
ToJames Bagley
SubjectRe: New Image Script!!!!
Date12 September 2005 14:42
James,

> it looks like this in explore (see attachment) How do I
> get it to show a New sign like the one below (see Attachment)

Need to make sure the src set here
foo.setAttribute('src','..\/..\/news.gif');
is the same as you would set here:
<img src="../../news.gif">
note that forward slashes / should be written as \/

and you probably want to change the style to remove the border. put this
after the "foo.setAttribute('src'..." line:
foo.style.border = 'none';

If you still can't get it working, put it on a real web site, and send me
the address.
FromJames Bagley
ToMe
SubjectRe: New Image Script!!!!
Date13 September 2005 10:16
Just wanted to say thanks for you help on the script. I have got it to
work fine now. It looks great.
Thanks
James
FromJames Bagley
ToMe
SubjectTwo scrips don't work together!!!!
Date1 November 2005 11:40
Hi 
I have been trying to put this script

<script src="addDateText.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
  if( !document.createElement || !document.createTextNode ) { return; }
  var foo = document.createElement('img');
  foo.setAttribute('src','..\/..\/news.gif');
  foo.setAttribute('alt','New');
  addDateText(0,5,'a',2,foo);
};
</script>
<a href="bar" title="Created 8 Sep 2005">baz</a>

With this one

[Ed. The folowing script snippet is quoted here only because this is how
it was sent to me in this email. It may be copyrighted, and is not covered
by my own license. Aside from that fact, I recommend you do not use this
script, since it is very poorly written, and has problems in several
browsers.]

3 parts to this script
Part 1, place inside head tags
=================================================================

<SCRIPT LANGUAGE="JavaScript">
<!-- begin script
function netie(net, ie) {
  if ((navigator.appVersion.substring(0,3) >= net && navigator.appName
== 'Netscape' && net != -1) || (navigator.appVersion.substring(0,3) >=
ie && navigator.appName.substring(0,9) == 'Microsoft' && ie != -1))
    return true;
else return false;
}
//  end script -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Start script
function transitionTxt() {
  if (idTransTxt.filters.item(0).status == 0) {
    idTransTxt.filters.item(0).apply();
    idTransTxt.style.visibility = "visible";
    idTransTxt.filters(0).play();
  }
}
//  End script -->
</SCRIPT>

===================================================================
part 2 - place in your opening body tag
===================================================================
onLoad="netie(-1,4)?transitionTxt():null"

or

<BODY onLoad="netie(-1,4)?transitionTxt():null">

===================================================================
part 3 - place inside your body where you want it to display
===================================================================

<DIV ID="idTransTxt" STYLE="position:relative; left:0; height:240;
width:720; color:#000000; font-size:10; font-family:Times New Roman;
filter:revealTrans(Duration=5, Transition=13); visibility:hidden">
Welcome to A1Javascript Resources!</DIV>

But the first one seems to work but the other one doesn't. Is there away
of making them both work?
Regards
James Bagley
FromMe
ToJames Bagley
SubjectRe: Two scrips don't work together!!!!
Date1 November 2005 13:06
James,

> window.onload = function () {

There is only one onload function handler. if you want two things to happen,
you have to put them both in the same handler function.

>   if ((navigator.appVersion.substring(0,3) >= net && navigator.appName
> == 'Netscape' && net != -1) || (navigator.appVersion.substring(0,3) >=
> ie && navigator.appName.substring(0,9) == 'Microsoft' && ie != -1))

what a thoroughly useless piece of garbage. Opera (for example - it is not
alone here) will be misidentified as IE. Sniffing is a very bad way to do
this. Check for the capability before you use it. Also, the script provides
no fallback for nonIE browsers (so I saw absolutely nothing when I tried the
example :) )

I suspect this is someone else's script you have copied, but here is what I
recommend you use - it will run both the scripts:

<script src="addDateText.js" type="text/javascript"></script>
<script type="text/javascript">
window.onload = function () {
 //first, my script (adjusted so it can continue, even if this fails)
 if( document.createElement && document.createTextNode ) {
  var foo = document.createElement('img');
  foo.setAttribute('src','..\/..\/news.gif');
  foo.setAttribute('alt','New');
  addDateText(0,5,'a',2,foo);
 }
 //now their script, adjusted so it does not use a sniffer
 if( window.idTransTxt && idTransTxt.filters ) {
  if(idTransTxt.filters.item(0).status == 0) {
   idTransTxt.filters.item(0).apply();
   idTransTxt.style.visibility = "visible";
   idTransTxt.filters(0).play();
  }
 } else {
  document.getElementById('idTransTxt').style.visibility = 'visible';
 }
};
</script>
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.