Help - Search - Members - Calendar
Full Version: HTML Include File / Java Script not refreshing
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
RynDog
I am using include file coding on some of my HTML pages (<!--#include file="filename.shtml" -->). The inlcude page loads up just fine, however, inside that include file is a Java Script code that displays random text when the page is reloaded. The script ONLY works if you hit the REFRESH button on a browser. If you click any of the internal links on the page, the script does not refresh the random text. I have tried some of the following things to try and force a refresh on the pages:

<META HTTP-EQUIV="expires" CONTENT="Wed, 03 Nov 1999 12:21:14 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta http-equiv="Cache-Control" Content="no-cache">

I have also tried changing the link to the full url of the page, instead of the internal regular link without the http://

Any thoughts on how I can achieve a refresh for the script in my includes page?

If I can provide any more information, please let me know. If you would like to see the site in action, you may do so at www.48hourgraphicdesigns.com/web, the TESTOMONIALS in the right side column you will notice does not change when clicking on any links with in the page, but it does if you press 'refresh' on the browser.

Thanks in advance!
RynDog
I should also mention, to determine that its not the script, I have made a 'test refresh' link on the included page, and it seems to work fine reloading that page by itself (which I have left on for you to see).
pandy
So how are you doing this? Why is the script file called rantex.php? Do you have a PHP script that generates random JS? unsure.gif
RynDog
QUOTE(pandy @ Nov 2 2009, 11:51 PM) *

So how are you doing this? Why is the script file called rantex.php? Do you have a PHP script that generates random JS? unsure.gif


Yes, let me be more specific on how Im using this:

In all my pages I am using the:

CODE
<!--#include file="right_side_bar.shtml" -->


The right_side_bar.shtml has the script code refering to the php script:

CODE
<script type="text/javascript" src="http://www.48hourgraphicdesigns.com/web/rantex.php"></script>


Which refers to rantex.php:

CODE
<?php
/*******************************************************************************
*  Title: Random text script (RanTex)
*  Version: 1.0 @ January 4, 2009
*  Author: Klemen Stirn
*  Website: http://www.phpjunkyard.com
********************************************************************************

*  COPYRIGHT NOTICE
*  Copyright 2009 Klemen Stirn. All Rights Reserved.
*
*  This script may be used and modified free of charge by anyone
*  AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT.
*  By using this code you agree to indemnify Klemen Stirn from any
*  liability that might arise from it's use.
*
*  If you are using this script you are required to place a link
*  to PHPJunkyard on your website. You will find some link suggestions here:
*  http://www.phpjunkyard.com/link2us.php
*
*  Selling the code for this program, in part or full, without prior
*  written consent is expressly forbidden.
*
*  Obtain permission before redistributing this software over the Internet
*  or in any other medium. In all cases copyright and header must remain
*  intact. This Copyright is in full effect in any country that has
*  International Trade Agreements with the United States of America or
*  with the European Union.
*******************************************************************************/

/*******************************************************************************
*  SETTINGS
*
*  See readme.htm file for further instructions!
*******************************************************************************/

/* File, where the random text/quotes are stored one per line */
$settings['text_from_file'] = 'quotes.txt';

/*
   If you prefer you can list quotes that RanTex will choose from here.
   In this case set above variable to $settings['text_from_file'] = '';
*/
$settings['quotes'] = array(
'First quote',
'Multi
line
quote',
'Second quote',
'Third quote',
'Some text with <b>HTML</b> code!',
'Any single quotes \' must be escaped with a backslash',
'A quote with a <a href="http://www.phpjunkyard.com">link</a>!',
);

/*
   How to display the text?
   0 = raw mode: print the text as it is, when using RanTex as an include
   1 = Javascript mode: when using Javascript to display the quote
*/
$settings['display_type'] = 1;

/* Allow on-the-fly settings override? 0 = NO, 1 = YES */
$settings['allow_otf'] = 1;

/*******************************************************************************
*  DO NOT EDIT BELOW...
*
*  ...or at least make a backup before you do!
*******************************************************************************/

/* Override type? */
if ($settings['allow_otf'] && isset($_GET['type']))
{
    $type = intval($_GET['type']);
}
else
{
    $type = $settings['display_type'];
}

/* Get a list of all text options */
if ($settings['text_from_file'])
{
    $settings['quotes'] = file($settings['text_from_file']);
}

/* If we have any text choose a random one, otherwise show 'No text to choose from' */
if (count($settings['quotes']))
{
    $txt = $settings['quotes'][array_rand($settings['quotes'])];
}
else
{
    $txr = 'No text to choose from';
}

/* Output the image according to the selected type */
if ($type)
{
    /* New lines will break Javascript, remove any and replace them with <br /> */
    $txt = nl2br(trim($txt));
    $txt = str_replace(array("\n","\r"),'',$txt);
    echo 'document.write(\''.addslashes($txt).'\')';
}
else
{
    echo $txt;
}
?>


Does that help?



Tom H.
Since you have PHP available, I would try using it rather than SSI to do your initial include. I have had difficulty nesting includes of different types.
RynDog
QUOTE(Tom H. @ Nov 3 2009, 06:22 AM) *

Since you have PHP available, I would try using it rather than SSI to do your initial include. I have had difficulty nesting includes of different types.


Can you refer me to a tutorial on how to achieve this?
pandy
The include shouldn't affect this. Must be some kind of caching issue. wacko.gif
RynDog
QUOTE(pandy @ Nov 3 2009, 10:40 AM) *

The include shouldn't affect this. Must be some kind of caching issue. wacko.gif


Anymore information I can provide?

I would also be willing to find another script that would work better. End result is I just want to have text displayed in a random/rotating manner when the page is refreshed (quote from testomonials).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.