Javascript - Show date on page.

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
Smee
 
 
Posts: 108
Joined: Fri Mar 02, 2018 11:03 pm

Javascript - Show date on page.

Post by Smee »

I've used the following script for years with a static page, but the site is being rebuilt with WWB. I've tried to check out the forum, but as it does not allow "search terms in quotes" I can enter javascript and date, but the links are as wide as the web itself.

Here's the script I use. I insert an html fragment placing the code between the head tags. The id of the html fragment is "frag_1" in my old editor. Has worked flawlessly for since 20011, and still works today --- except in WWB I can't move the HTML fragment to a "layout grid" or other container --- centered. If I remove the "style" information, I get nothing at all.

Want to put inside a layout grid so that it moves relative to the grid it's placed in.

Any ideas?

Code: Select all

<div id="frag_1"  style="position:absolute;left:428px;top:478px;width:158px;height:21px;">
	<script type="text/javascript"><!--
function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
}

var months = new makeArray('January','February','March','April','May',
'June','July','August','September','October','November','December');
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

document.write(months[month] + " " +day + "," + " " + year);
//--></script>
</div>
MGD4me
 
 
Posts: 281
Joined: Tue May 02, 2017 11:56 pm
Location: British Columbia, Canada

Re: Javascript - Show date on page.

Post by MGD4me »

In the Toolbox, look for "Ready to use Java scripts". There you will find "Basic Date", which will give you what you need. Drag a box where you would like the date to appear. That's it.

The following script will automatically be inserted for you:

Code: Select all

<script>
   var now = new Date();
   var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
   var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
   var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();
   var year = (now.getYear() < 1000) ? now.getYear() + 1900 : now.getYear();
   today = days[now.getDay()] + ", " + months[now.getMonth()] + " " + date + ", " + year;
   var basicdate = document.getElementById('basicdate');
   basicdate.innerHTML = today;
</script>
Smee
 
 
Posts: 108
Joined: Fri Mar 02, 2018 11:03 pm

Re: Javascript - Show date on page.

Post by Smee »

Thanks! I appreciate your assistance.
Smee
 
 
Posts: 108
Joined: Fri Mar 02, 2018 11:03 pm

Re: Javascript - Show date on page.

Post by Smee »

I've drug the box out, tried putting it on a blank page.

I've drug the box into a flex grid.

I've drug the box into a flex container.

I've drug the box into an HTML fragment.

I've drug the box into a text box.

DOES NOT WORK IN ANY OF THESE WAYS! There must be something I missed. Something that wasn't included in the instructions. Something that wasn't included in the help.
User avatar
Pablo
 
Posts: 23419
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Javascript - Show date on page.

Post by Pablo »

If you use this code inside a layout grid then you will need to define a font size. The default font-size of a layout grid is zero. So, your code will inherit this from the container.
Also, your code should use relative position/size. You cannot place an absolute element inside a flexible container.

Note that there is no support on custom code. But you code will be inserted "AS IS". So, if it does not work then either the code is invalid or it conflicts with other code on the page.
Smee
 
 
Posts: 108
Joined: Fri Mar 02, 2018 11:03 pm

Re: Javascript - Show date on page.

Post by Smee »

I'm using the built in java script (ready to use java scripts) in the toolbox.

I've placed it on a page with nothing else on the page, it does not display in any browser.

It does, however, display fine in the editor of both WB 14 and WB 15.

Font size is set to 12 when it is dropped on the page.

Image

This is dropped on a new page. No grid, no other code, no layer, nothing but this javascript.

It must be that there is something else I need to do, but I haven't been able to determine what it is.

Been struggling with inputting this for some time. Stopped for a couple months, going on to other things on this site as well as life hoping that I would figure it out but haven't.
User avatar
Pablo
 
Posts: 23419
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Javascript - Show date on page.

Post by Pablo »

Maybe you have used conflicting settings in Tools -> Options -> HTML ?
Click 'Reset Settings' and try again.

If that does not work then please publish the page so I can see if anything is wrong.
Smee
 
 
Posts: 108
Joined: Fri Mar 02, 2018 11:03 pm

Re: Javascript - Show date on page.

Post by Smee »

THANKS! The reset solved the problem.

At some point I must have put a check in "generate external JS file for page specific scripts" because it was checked. Don't remember doing it but I must have.
User avatar
AliGW
 
 
Posts: 216
Joined: Thu Dec 19, 2024 3:41 pm

Re: Javascript - Show date on page.

Post by AliGW »

I can't find the option mentioned in the toolbox, so maybe things have changed since this thread was started,

Is there still a way to automatically insert today's date on to a web page, please?

EDIT: What I am wanting to do is have a text item on the page that says something like "This page was last updated at 17:15 BST (or GMT) on Saturday 03 May 2025."

Thanks.
Ali
Retired, but still loving to learn & very busy.
https://alisongwright.me.uk
Novice with WWB, but was an avid user of Serif WebPlus before.
Fairly expert at Microsoft Excel (but not VBA).
User avatar
Pablo
 
Posts: 23419
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Javascript - Show date on page.

Post by Pablo »

"Ready to use JavaScripts" is still an option in the toolbox.
Or if you referring to the HTML object then this also still exists.
User avatar
BaconFries
 
 
Posts: 5931
Joined: Thu Aug 16, 2007 7:32 pm

Re: Javascript - Show date on page.

Post by BaconFries »

It is not in the Toolbox it is in Tools -> Options -> HTML

Image

Or if you wish to use the mentioned code then you can use the following:
https://www.wysiwygwebbuilder.com/add_html.html

In the Toolbox, look for "Ready to use Java scripts". There you will find "Basic Date or Ready-to-Use Javascript "Last Modified"
User avatar
AliGW
 
 
Posts: 216
Joined: Thu Dec 19, 2024 3:41 pm

Re: Javascript - Show date on page.

Post by AliGW »

I'm sorry, I don't understand.

What am I meant to be looking for under Tools | Options | HTML?

And as I said above, in the Toolbox, I see no Ready to use Java Sceripts at all.

I'm missing something, obviousy, but I don't know what that is.

EDIT: I found the javascripts under Miscellaneous, thanks.

But I don't see how I can change the date to Saturday 03 May 2025 instead of Saturday, May 03, 2025, nor do I see how to add any custom text. I can't find how to preview the underlying code, either.

EDIT AGAIN: I have just previewed both the time and date options and they aren't actually what I want. Maybe I should start anew thread for this. Thanks again.
Ali
Retired, but still loving to learn & very busy.
https://alisongwright.me.uk
Novice with WWB, but was an avid user of Serif WebPlus before.
Fairly expert at Microsoft Excel (but not VBA).
User avatar
BaconFries
 
 
Posts: 5931
Joined: Thu Aug 16, 2007 7:32 pm

Re: Javascript - Show date on page.

Post by BaconFries »

It is possible that you may have enabled "Easmode"not saying you have but if you have it will hide Ready to use JavaScript
See the following
https://wysiwygwebbuilder.com/easymode.html
User avatar
AliGW
 
 
Posts: 216
Joined: Thu Dec 19, 2024 3:41 pm

Re: Javascript - Show date on page.

Post by AliGW »

No - see my edits above.

I'm going to start a new thread - I see now that this one isn't the same thing that I am wanting to do.

Thanks again.
Ali
Retired, but still loving to learn & very busy.
https://alisongwright.me.uk
Novice with WWB, but was an avid user of Serif WebPlus before.
Fairly expert at Microsoft Excel (but not VBA).
User avatar
BaconFries
 
 
Posts: 5931
Joined: Thu Aug 16, 2007 7:32 pm

Re: Javascript - Show date on page.

Post by BaconFries »

@Ali do you want it to read like this?
This page was last updated on: Sat May 03 2025 18:23:02 GMT+0100 (British Summer Time)
User avatar
AliGW
 
 
Posts: 216
Joined: Thu Dec 19, 2024 3:41 pm

Re: Javascript - Show date on page.

Post by AliGW »

Yes - the wording I want is in my first post to this thread, but I have now started a new thread for this because it isn't actually the same request as this thread.
Ali
Retired, but still loving to learn & very busy.
https://alisongwright.me.uk
Novice with WWB, but was an avid user of Serif WebPlus before.
Fairly expert at Microsoft Excel (but not VBA).
Post Reply