Page 1 of 1

Javascript - Show date on page.

Posted: Sat Jul 06, 2019 10:42 pm
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>

Re: Javascript - Show date on page.

Posted: Sat Jul 06, 2019 11:35 pm
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>

Re: Javascript - Show date on page.

Posted: Sat Jul 06, 2019 11:48 pm
by Smee
Thanks! I appreciate your assistance.

Re: Javascript - Show date on page.

Posted: Sat Aug 17, 2019 2:23 am
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.

Re: Javascript - Show date on page.

Posted: Sat Aug 17, 2019 6:12 am
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.

Re: Javascript - Show date on page.

Posted: Sat Aug 17, 2019 1:07 pm
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.

Re: Javascript - Show date on page.

Posted: Sat Aug 17, 2019 1:23 pm
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.

Re: Javascript - Show date on page.

Posted: Sat Aug 17, 2019 6:38 pm
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.

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 4:26 pm
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.

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:01 pm
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.

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:08 pm
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"

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:24 pm
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.

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:37 pm
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

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:38 pm
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.

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:41 pm
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)

Re: Javascript - Show date on page.

Posted: Sat May 03, 2025 5:51 pm
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.