Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Time dependent script - Run different script depending on time of day


RMD27

Recommended Posts

Hi

 

I have the "ask a product question" contribution

 

I also have a live messenger installation

 

I want the live messenger to show during office hours and the ask a product question contribution to run when we are closed,

 

This is what I have come up with

 

 <!--webbot bot="HTMLMarkup" startspan --><script type="text/javascript">var current= new Date()
var day_night=current.getHours()
if (day_night<=12)
document.write("<!-- webim button --><a href="/open-web-messenger/client.php?locale=en&style=simplicity" target="_blank" onclick="if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open('/open-web-messenger/client.php?locale=en&style=simplicity&url='+escape(document.location.href)+'&referrer='+escape(document.referrer), 'webim', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;"><img src="/open-web-messenger/b.php?i=webim&lang=en" border="0" width="163" height="61" alt=""/></a><!-- / webim button -->")
else
document.write("<font size="1"><br><?php echo tep_image(DIR_WS_IMAGES . 'person.jpg'); ?><?php echo '<a href="' . tep_href_link(FILENAME_ASK_QUESTION, 'products_id='.$product_info['products_id']) . '">' . TEXT_ASK_QUESTION . '</a>'; ?></font>")</script><!--webbot bot="HTMLMarkup" endspan -->  

 

 

But I cant get it to work. With the current set up it is a blank

 

This is what I am basing the time dependent script on http://www.tutorials...JavaScript.html . I thought it would be easy to substitute images for code!

 

I am trying to do this in the product description / product_info page

 

If someone can give me some pointers it would be appreciated.

Link to comment
Share on other sites

Hi there,

 

This worked for me (with a simplified script output)-

 

<script type="text/javascript">

var current= new Date()

var day_night=current.getHours()

if (day_night>=12){

document.write("Hello")

}else{

document.write("Goodbye")

}

</script>

 

Hope it helps!

Matt

Link to comment
Share on other sites

Hi there,

 

This worked for me (with a simplified script output)-

 

<script type="text/javascript">

var current= new Date()

var day_night=current.getHours()

if (day_night>=12){

document.write("Hello")

}else{

document.write("Goodbye")

}

</script>

 

Hope it helps!

 

Hi

 

Yeah, I could get it to show the text, but when I bolt either code in it goes blank

Link to comment
Share on other sites

You forget one important tidbit.

 

Javascript is "client side" not "server side".

 

Meaning the time returned is the time on the visitor's PC not your server time.

 

You could do something like this

 

You'd need to change the code towards the bottom:

 

// Store open! 
 } else { 
// Store closed! 
       tep_redirect(tep_href_link(FILENAME_STORE_NOT_OPEN)); 
 } 

To something like this:

 

// Store open!
// delete this line and put your code here to display when the store is open
 } else { 
// Store closed!
// delete this line and put your code here to display when the store is closed
 } 

And you wouldn't put it in the checkout files, put it where your current code is.

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Try this code:

 

// Store open!
?>
<!-- webim button -->
<a href="/open-web-messenger/client.php?locale=en&style=simplicity" target="_blank" onclick="if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open('/open-web-messenger/client.php?locale=en&style=simplicity&url='+escape(document.location.href)+'&referrer='+escape(document.referrer), 'webim', 'toolbar=0,scrollbars=0,location=0,status=1,menubar=0,width=640,height=480,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;">
<img src="/open-web-messenger/b.php?i=webim〈=en" border="0" width="163" height="61" alt=""/></a>
<!-- webim button -->
<?php
 } else {  
// Store closed! 
?>
<!-- / webim button --> 
<br>
<font size="1">
<?php
echo tep_image(DIR_WS_IMAGES . 'person.jpg');
echo '<a href="' . tep_href_link(FILENAME_ASK_QUESTION, 'products_id='.$product_info['products_id']) . '">' . TEXT_ASK_QUESTION . '</a>';
?>
</font>
<!-- / webim button --> 
<?php
 } 

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...