Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21040 > unrolled thread
| Started by | Swifty <steve.j.swift@gmail.com> |
|---|---|
| First post | 2013-08-24 09:46 +0100 |
| Last post | 2013-08-28 19:32 +0100 |
| Articles | 10 — 4 participants |
Back to article view | Back to comp.lang.javascript
Passing parameter to external script Swifty <steve.j.swift@gmail.com> - 2013-08-24 09:46 +0100
Re: Passing parameter to external script Swifty <steve.j.swift@gmail.com> - 2013-08-24 09:54 +0100
Re: Passing parameter to external script Martin Honnen <mahotrash@yahoo.de> - 2013-08-24 11:00 +0200
Re: Passing parameter to external script Swifty <steve.j.swift@gmail.com> - 2013-08-24 10:26 +0100
Re: Passing parameter to external script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-24 12:59 +0100
Re: Passing parameter to external script Swifty <steve.j.swift@gmail.com> - 2013-08-24 17:27 +0100
Re: Passing parameter to external script Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-24 19:49 +0100
Re: Passing parameter to external script Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-08-25 23:45 +0100
Re: Passing parameter to external script Swifty <steve.j.swift@gmail.com> - 2013-08-27 20:46 +0100
Re: Passing parameter to external script Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-08-28 19:32 +0100
| From | Swifty <steve.j.swift@gmail.com> |
|---|---|
| Date | 2013-08-24 09:46 +0100 |
| Subject | Passing parameter to external script |
| Message-ID | <kv9rtr$ccu$1@speranza.aioe.org> |
Can the construct:
<SCRIPT SRC=/lastupdated.js></SCRIPT>
… be modified to pass a parameter to lastused.js ?
I suspect the answer is "No", but since I rank last but three in
JavaScript coding skill (global survey) I decided to ask people who know.
Presumably, the answer is to define a function, lastupdated() in
lastupdated.js and then use:
<SCRIPT>lastupdated('Swifty')</SCRIPT>
inline the HTML?
Out of curiosity, are there any ghastly errors in my lastused.js,
bearing in mind that it works for me?
// Swifty's lastused.js
function LastUpdated(Whom)
{
if (Whom === undefined) {Whom = "Swifty";}
var DayOfWeek = new Initialize("Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday" );
var MonthName = new Initialize("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October", "November",
"December");
var LastModifiedDate = new Date(document.lastModified);
document.write("<SMALL>This page was last updated ");
document.write(DayOfWeek[(LastModifiedDate.getDay() + 1 )] ,", ");
document.write(MonthName[(LastModifiedDate.getMonth() + 1)] ," ");
year=LastModifiedDate.getYear();
if (year<100) year+=100;
if (year<1000) year+=1900;
document.write( LastModifiedDate.getDate() ,", " ,( year ) );
hours= LastModifiedDate.getHours();
document.write( " at ", ((hours < 10) ? "0" : "") + hours )
minutes= LastModifiedDate.getMinutes();
document.write( ((minutes < 10) ? ":0" : ":") + minutes );
if (Whom !== '') {document.write(" by ",Whom,".");}
}
function Initialize()
{ this.length = Initialize.arguments.length
for ( var i = 0; i < this.length; i++ ) this[ i + 1 ] =
Initialize.arguments[ i ]
}
--
Steve Swift
http://www.swiftys.org.uk/
[toc] | [next] | [standalone]
| From | Swifty <steve.j.swift@gmail.com> |
|---|---|
| Date | 2013-08-24 09:54 +0100 |
| Message-ID | <kv9sc8$deb$1@speranza.aioe.org> |
| In reply to | #21040 |
On 24/08/2013 09:46, Swifty wrote:
> document.write("<SMALL>This page was last updated ");
I'll pick the low-hanging fruit myself - I corrected the lack of the
closing </SMALL>
--
Steve Swift
http://www.swiftys.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | Martin Honnen <mahotrash@yahoo.de> |
|---|---|
| Date | 2013-08-24 11:00 +0200 |
| Message-ID | <52187634$0$9524$9b4e6d93@newsspool1.arcor-online.net> |
| In reply to | #21040 |
Swifty wrote:
> Can the construct:
>
> <SCRIPT SRC=/lastupdated.js></SCRIPT>
>
> … be modified to pass a parameter to lastused.js ?
Well you don't pass parameters to complete script files with Javascript,
you pass parameters to functions or methods defined in your Javascript
code. Whether you define the Javascript code inline or in an external
file does not change the way you pass parameters to functions or methods.
> Presumably, the answer is to define a function, lastupdated() in
> lastupdated.js and then use:
>
> <SCRIPT>lastupdated('Swifty')</SCRIPT>
>
> inline the HTML?
You can access any function defined in your external file, there is no
need to give it a name corresponding to the file name.
And even the second script does not have to be inline, if you have
<script src="foo.js"></script>
<script src="bar.js"></script>
and foo.js defines function "f1" then bar.js can call that function.
[toc] | [prev] | [next] | [standalone]
| From | Swifty <steve.j.swift@gmail.com> |
|---|---|
| Date | 2013-08-24 10:26 +0100 |
| Message-ID | <kv9u8o$i1u$1@speranza.aioe.org> |
| In reply to | #21042 |
On 24/08/2013 10:00, Martin Honnen wrote: > Well you don't pass parameters to complete script files with Javascript, > you pass parameters to functions or methods defined in your Javascript code. Thank you, so far, so good! I put initialise() in with LastUsed() inside lastused.js as LastUsed() requires initialise() - and nothing else does. I'm feelong optimistic here. With a bit of extra effort, I could perhaps improve my JavaScript skill to "barely passable". :-) Incidentally, I "borrowed" the bulk of lastused.js from a sample on the web; I couldn't reproduce it in an exam. -- Steve Swift http://www.swiftys.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2013-08-24 12:59 +0100 |
| Message-ID | <0.dd222275a65ffd470b32.20130824125904BST.87vc2vl2pj.fsf@bsb.me.uk> |
| In reply to | #21040 |
Swifty <steve.j.swift@gmail.com> writes: > Can the construct: > > <SCRIPT SRC=/lastupdated.js></SCRIPT> > > … be modified to pass a parameter to lastused.js ? > > I suspect the answer is "No", but since I rank last but three in > JavaScript coding skill (global survey) I decided to ask people who > know. Stretching the definition of "parameter" somewhat, there is a way, though it may not be practical. You can embed data into any HTML element using the new data-* attributes, and the script can find this data by looking in document.currentScript. However, I don't think currentScript is well supported. There are other ways for the script to "find itself" but I think they are all rather fragile. Do you know about the document.lastModified property? It could be useful to you. I don't know how widely supported it is, but a quick tests suggests it has better support than currentScript. I prefer to do all this sort of thing server-side, but that may not be an option for you. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Swifty <steve.j.swift@gmail.com> |
|---|---|
| Date | 2013-08-24 17:27 +0100 |
| Message-ID | <kvamu0$l28$1@speranza.aioe.org> |
| In reply to | #21045 |
On 24/08/2013 12:59, Ben Bacarisse wrote: > Do you know about the document.lastModified property? It could be > useful to you. I don't know how widely supported it is, but a quick > tests suggests it has better support than currentScript. > > I prefer to do all this sort of thing server-side, but that may not be > an option for you. I may be showing my ignorance here (see http://www.swiftys.org.uk/wiz?574) but my sample JavaScript uses document.Lastmodified and I have no recollection of encountering currentScript. However, when pressed on "do you know abut the document.lastModified property?" my answer would have to be "not much", as that was part of the original script that I cribbed (and have changed little). I know that it returns the date that the HTML was last changed, and that this information is passed from server to browser in the HTTP headers. The mechanism seems fully robust, and very widely supported. However, I can't imagine anyone getting sufficient worked up to contact me when the phrase "This page was last updated" is followed by nothing (the result when the JavaScript fails on: "DayOfWeek[(LastModifiedDate.getDay() + 1 )]" I would perhaps use server-side to detect the changed-date of my index.html file on the various webservers where I operate, but I suspect this would require PHP to be activated on the servers. My http://www.swiftys.org.uk/index.html comes from a server where PHP is not activated, and the SysAdmin of the site did me a huge favour when I requested certain features, so I try not to rock the boat by asking for more. It's a good idea to generate the "This document last changed [date]" in the CGI scripts, where possible, and I will enjoy implementing this change. I suspect my CGI scripts would not generate the necessary HTTP header for document.lastModified to work, anyway. -- Steve Swift http://www.swiftys.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2013-08-24 19:49 +0100 |
| Message-ID | <0.06b415d1edc8f2b68ee2.20130824194900BST.87a9k6kjqb.fsf@bsb.me.uk> |
| In reply to | #21046 |
Swifty <steve.j.swift@gmail.com> writes: > On 24/08/2013 12:59, Ben Bacarisse wrote: >> Do you know about the document.lastModified property? It could be >> useful to you. I don't know how widely supported it is, but a quick >> tests suggests it has better support than currentScript. >> >> I prefer to do all this sort of thing server-side, but that may not be >> an option for you. > > I may be showing my ignorance here (see > http://www.swiftys.org.uk/wiz?574) but my sample JavaScript uses > document.Lastmodified and I have no recollection of encountering > currentScript. No, I just did not read the script! No harm done, though. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2013-08-25 23:45 +0100 |
| Message-ID | <CLRWZWLtjoGSFwix@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #21040 |
In comp.lang.javascript message <kv9rtr$ccu$1@speranza.aioe.org>, Sat,
24 Aug 2013 09:46:50, Swifty <steve.j.swift@gmail.com> posted:
>Can the construct:
>
> <SCRIPT SRC=/lastupdated.js></SCRIPT>
>
>… be modified to pass a parameter to lastused.js ?
That depends on what you mean by "parameter" - just assign a value to a
"var" in the called script; the calling page will see the "var".
>I suspect the answer is "No", but since I rank last but three in
>JavaScript coding skill (global survey) I decided to ask people who
>know.
>
>Presumably, the answer is to define a function, lastupdated() in
>lastupdated.js and then use:
>
> <SCRIPT>lastupdated('Swifty')</SCRIPT>
>
>inline the HTML?
>
>Out of curiosity, are there any ghastly errors in my lastused.js,
>bearing in mind that it works for me?
Yes. Answered in another group.
It was not a multi-post, just a multi- tempt-to-read-that-code.
Never blindly copy date code, or any other code, from unknown Web
authors, since to do worse oneself often takes considerable effort.
--
(c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05.
Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
[toc] | [prev] | [next] | [standalone]
| From | Swifty <steve.j.swift@gmail.com> |
|---|---|
| Date | 2013-08-27 20:46 +0100 |
| Message-ID | <kvivml$qk1$1@speranza.aioe.org> |
| In reply to | #21049 |
On 25/08/2013 23:45, Dr J R Stockton wrote: > Never blindly copy date code, or any other code, from unknown Web > authors, since to do worse oneself often takes considerable effort. In my case, "works" trumps "doesn't work" every time. At that time in my use of Javascript, nothing I tried from scratch worked at all. Now I'm no longer employed to write webpages, my JavaScript skill is dwindling again. I have more time to learn it, but unfortunately that is more than offset by failing memory (mine, not Intel's, but I had my first DIMM failure a few weeks ago, when one of my system's four 4Gb DIMMs failed the day after I came back off holiday.) -- Steve Swift http://www.swiftys.org.uk/
[toc] | [prev] | [next] | [standalone]
| From | Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> |
|---|---|
| Date | 2013-08-28 19:32 +0100 |
| Message-ID | <1qpLRg+LJkHSFwvj@invalid.uk.co.demon.merlyn.invalid> |
| In reply to | #21058 |
In comp.lang.javascript message <kvivml$qk1$1@speranza.aioe.org>, Tue, 27 Aug 2013 20:46:32, Swifty <steve.j.swift@gmail.com> posted: >On 25/08/2013 23:45, Dr J R Stockton wrote: >> Never blindly copy date code, or any other code, from unknown Web >> authors, since to do worse oneself often takes considerable effort. > >In my case, "works" trumps "doesn't work" every time. At that time in >my use of Javascript, nothing I tried from scratch worked at all. > >Now I'm no longer employed to write webpages, my JavaScript skill is >dwindling again. I have more time to learn it, but unfortunately that >is more than offset by failing memory (mine, not Intel's, but I had my >first DIMM failure a few weeks ago, when one of my system's four 4Gb >DIMMs failed the day after I came back off holiday.) If you find any truly useful JavaScript Gregorian/Julian Date/Time code missing from my Web site, RSVP and I'll try to remedy the situation. Start at <http://www.merlyn.demon.co.uk/js-dates.htm> -- (c) John Stockton, nr London, UK. E-mail, see Home Page. Turnpike v6.05. Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web