2015-08-17 21 views
-1
<script src="http://gd.geobytes.com/gd?after=-1&amp;variables=GeobytesLocationCode" language="Javascript"></script> 
<script language="Javascript"> 
    if(typeof(sGeobytesLocationCode)=="undefined") 
    { 
     var sGeobytesLocationCode="unknown"; 
    } 
    if(sGeobytesLocationCode=="LTVLVilnius") 
    { 
     document.write("<META HTTP-EQUIV='Refresh' CONTENT='0; URL=test123'>"); 
    } 
</script> 

此代码工作,但循环 - 页面重定向(无限次)。如何让这段代码只执行一次?如何禁用代码循环?

+1

你的目标是? –

+0

如何让这段代码只执行一次? – Legomyego

+0

我只想做一个重定向,就这些了。 – Legomyego

回答

0

您可以通过添加一个哈希(如#stop)的URL阻止它:

<META HTTP-EQUIV='Refresh' CONTENT='0; URL=test123#stop'> 

然后,在你的第二个if条件,检查该哈希没有定义:

if(sGeobytesLocationCode=="LTVLVilnius" && window.location.hash != '#stop') 

您也可以使用cookie或localStorage。无论如何,任何“持久性”存储允许您重新加载页面,并仍然知道您之前做过什么。