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:30 pm
by Smee
Hmm.... moved to off topic?
Well, at least someone read it who was qualified to answer --- even if they did send it to the off topic section.
Wow! Look at all the cool cobwebs!
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: Sun Jul 07, 2019 12:07 am
by Smee
Displays in WWB, but in preview there is nothing.
uploaded the page to the server, same thing. Should appear between the "Ashley County News" and the "Local News, Community News" etc.
https://www.ahgweb.com/qlite/news.html
Re: Javascript - Show date on page.
Posted: Sun Jul 07, 2019 12:15 am
by MGD4me
Me again ...
Did you "draw" a box where you want the date to appear on the web page"
If "yes", double click inside the box and it will preview exactly how the date will appear. The date should also display in your workspace, PLUS Preview mode.
I had a look at your web site, and "something" (tm) is missing. I can see that "Basic Date" has been selected, but no script. Weird !
Code: Select all
<div id="wb_JavaScript1">
<div id="basicdate"></div>
</div>
</div>
Whereas, it
should look like this:
Code: Select all
<div id="wb_JavaScript1">
<div id="basicdate"></div>
<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>
</div>
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.
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.