Open new window if user hasn't seen an article
I would like to create a function where a new window pops up to encourage people to answer the question of the week. But I don't want to overly annoy people.
I added the article "Question of the week #1" in the discussion area, then featured the article. I created a custom component on the home page to open a new window to the page of the featured article. The problem is:
- I don't want the window to open everytime they visit the home page, only if they haven't seen the window or article yet
- Openning a new window in javascript causes browsers to block the new window
Any suggestions?
Thanks,
Jonathan
Hi Jonathan,
What you're experiencing is likely a data truncation issue with these two lines:<#assign date_visit = rest("/users/id/" + my_userid + "/last_visit_time").value?datetime("yyyy-MM-dd") /> <#assign my_topic_posttime = topic.post_time?datetime("yyyy-MM-dd") />
Because of the "yyyy-MM-dd" timestamp format, it's only picking up the year, month, and date. If you want a more specific date/time you'll need to alter this format (ie. to account for hours, minutes, seconds). Perhaps something like this: "yyyy-MM-dd'T'HH:mm:ssZ"
Hi Jonathan,
Since the REST API returns the date in GMT+0, I'd suggest getting "now" in GMT+0 as well instead of trying to convert the result to the local timezone.
Here's some sample code I came up with showing how to get the current time in GMT+0 (you'll probably be more interested in the milliseconds version):
<#assign utcDateTime = .now?iso_utc?datetime("yyyy-MM-dd'T'HH:mm:ss") /> <#assign utcDateTime_number = datesupport.setDate(utcDateTime).millisecondsAsString?number /> utcDateTime: ${utcDateTime}<br /> utcDateTime_number: ${utcDateTime_number}<br />
I hope this helps!