2013-09-25 3 views
0

У меня есть веб-сайт, который имеет случайные изображения каждый раз, когда загружается домашняя страница. Но проблема случайных изображений - она ​​все еще загружается, когда я снова нажимаю на главную страницу BUTTON. Точно, я хочу, чтобы случайные изображения отображались ТОЛЬКО, когда я обновляю домашнюю страницу, а не кнопку домашней страницы, как бы я это сделал?Случайное изображение на Refresh?

Вот следующий код:

JAVASCRIPT<Head> 
<script type="text/javascript"> 
var y1 = 20; 
(document.getElementById) ? dom = true : dom = false; 


var gallery = new Array(); 
gallery[0] = new  Array("earlywork001.jpg","earlywork002.jpg","earlywork003.jpg","earlywork004.jpg","earlywor k005.jpg"); 

function pickImageFrom(whichGallery) 
{ 
var idx = Math.floor(Math.random() * gallery[whichGallery].length); 
document.write('<a href="images/earlywork/' + gallery[whichGallery][idx] + '" class="highslide" onclick="return hs.expand(this, config1)"><img src="images/earlywork/' + gallery[whichGallery][idx] + '" width="402" height="180"></a>'); 
} 

function hideIt() { 
if (dom) {document.getElementById("popup").style.visibility='hidden';} 
} 

function showIt() { 
if (dom) {document.getElementById("popup").style.visibility='visible';} 
} 

function placeIt() { 
if (dom && !document.all) {document.getElementById("popup").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1)) + "px";} 
if (document.all) {document.all["layer1"].style.top = document.documentElement.scrollTop + (document.documentElement.clientHeight - (document.documentElement.clientHeight-y1)) + "px";} 
window.setTimeout("placeIt()", 10); } 
</script> 
</head> 

HTML<Body> 
<body onLoad="placeIt(); showIt()"> 
/*code*/ 
    <div id="content"><!--Start content--> 
    <div id="popup" style="position:absolute; left:140px; width:410px; height:20px; visibility:hidden"> 
    <div style="background-color:white; padding:3px; border:1px solid black"> 
    <span style="float:right; background-color:gray; color:white; font-weight:bold; width='20px'; text-align:center; cursor:pointer" onclick="javascript:hideIt()">&nbsp;X&nbsp;</span> 
    <script language="javascript">pickImageFrom(0);</script></div> 
    </div> 
    <img src="images/home.png" width="644" height="363" alt="home" class="content" /> 
    </div><!--End content--> 
    </div><!--End body content--> 
    /*code*/ 
+0

Какую кнопку «домашней страницы» вы имеете в виду? Кнопка браузера или одна на вашей странице, которую мы не видим? – guymid

+0

Я не включил мою домашнюю страницу здесь – Akimichi

ответ

0

Оберните ваш код в if:

if (document.URL == document.referrer) { 
// your code here 
} 

document.referrer получит Вас URL предыдущей страницы. Совместите его с текущим URL-адресом в document.URL. Если оба не совпадают, ваша страница была перенесена с другой страницы.

Смежные вопросы