0

I am using a random quotes script on my site which shows random quotes on every click on any site link. Example: random quote 1 on index, if i click login, it shows random quote 2, 3 or 4 and so on. But the problem is that, If this script is on, Whenever i click on any other page of site, such as login, register etc. page does not load normally but instead it loads with a blink.

Here is the script i am using, with the filename quotes.php in my site.

<?php
$quotes = 'Random Text 01
Random Text 02
Random Text 03
Random Text 04
Random Text 05
Random Text 06';
$split_array = explode("\n", $quotes);
$rand_keys = array_rand($split_array, 1);

header("content-type: application/x-javascript");
echo "<!--\n
document.write('{$split_array[$rand_keys]}');\n
//-->";

?>

And it shows up on overall_header.html These are the edits which i made in html file

<ul class="linklist leftside">
<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
<li><script type="text/javascript" src="quotes.php"></script></li><!-- ELSE --><li class="quotehead">Important Information from the Administrators --</li><li class="loggedout">Thank you for visiting our forum. Please login to enjoy the full features of our site.</li><!-- ENDIF -->
</ul>

Please tell me what bug in this script is causing blink on every page load.

Regards

HD3D
  • 9
  • 2
  • have you try not to document.write, but to a div? – cox Dec 28 '13 at 12:16
  • Can you specify what you mean with 'blink'? – Sbls Dec 28 '13 at 12:17
  • @cox, I am not a pro, I don't know how to use div, can you please make the changes for me? I got this script from a site that's why I don't know what changes will make it work flawlessly. – HD3D Dec 28 '13 at 12:44
  • @Sbls http://www.Thewarez.org here is the link of my site, please navigate to different pages of the site, you will see a blink while loading page. – HD3D Dec 28 '13 at 12:46
  • 1
    if you use jquery, instead of document.write(...) try $("#target_div_id").append("

    your content

    "); similar for plain js: var div = document.getElementById('target_div_id'); div.innerHTML = div.innerHTML + 'Extra stuff';(http://stackoverflow.com/questions/5677799/how-to-append-data-to-div-using-javascript)
    – cox Dec 28 '13 at 12:48
  • @cox Sadly, I can't understand any part of it, I will be really thankful if you can correct the bug in that script for me? – HD3D Dec 28 '13 at 12:54
  • echo ""; Of course, you must create a div with id div_id in the position where you want the text to appear – cox Dec 28 '13 at 12:57
  • @cox I used the above changes but sadly, site is still blinking on page load. – HD3D Dec 28 '13 at 13:07
  • I don't see all source. But adding content via ajax should involve only html/text and json, not js. application/json should be the mime type, alltought it may not solve the problem – cox Dec 28 '13 at 13:13
  • @cox I have updated the first post with full code, where you can see the edits i used in html file and quotes.php – HD3D Dec 28 '13 at 13:21
  • Is there anyone to help me? – HD3D Dec 29 '13 at 23:53
  • I can't access the provided link if you could edit your question by clarifying what you mean by blink, more ppl would interest in answering your question. – Adi Prasetyo May 09 '20 at 16:34

0 Answers0