Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使此弹出代码在一个站点上弹出50%,在另一个站点上弹出50%?_Javascript_Php - Fatal编程技术网

Javascript 如何使此弹出代码在一个站点上弹出50%,在另一个站点上弹出50%?

Javascript 如何使此弹出代码在一个站点上弹出50%,在另一个站点上弹出50%?,javascript,php,Javascript,Php,下面的代码是一个弹出代码,它将为给定的任何URL弹出一个窗口。我想能够使用此代码弹出50%一个网站,50%另一个网站。我不知道如何才能做到这一点。任何帮助都将不胜感激 <script type="text/javascript">var pics=[],stat=[],pic=[];</script> <script type="text/javascript"> if (top.location != self.location) t

下面的代码是一个弹出代码,它将为给定的任何URL弹出一个窗口。我想能够使用此代码弹出50%一个网站,50%另一个网站。我不知道如何才能做到这一点。任何帮助都将不胜感激

<script type="text/javascript">var pics=[],stat=[],pic=[];</script>
<script type="text/javascript">
    if (top.location != self.location)
        top.location.replace(self.location);
</script>
<script>
    var puShown = false;
    var PopWidth = 1370;
    var PopHeight = 800;
    var PopFocus = 0;
    var _Top = null;
    function GetWindowHeight() {
        var myHeight = 0;
        if( typeof( _Top.window.innerHeight ) == 'number' ) {
            myHeight = _Top.window.innerHeight;
        } else if( _Top.document.documentElement && _Top.document.documentElement.clientHeight ) {
            myHeight = _Top.document.documentElement.clientHeight;
        } else if( _Top.document.body && _Top.document.body.clientHeight ) {
            myHeight = _Top.document.body.clientHeight;
        }
        return myHeight;
    }
    function GetWindowWidth() {
        var myWidth = 0;
        if( typeof( _Top.window.innerWidth ) == 'number' ) {
            myWidth = _Top.window.innerWidth;
        } else if( _Top.document.documentElement && _Top.document.documentElement.clientWidth ) {
            myWidth = _Top.document.documentElement.clientWidth;
        } else if( _Top.document.body && _Top.document.body.clientWidth ) {
            myWidth = _Top.document.body.clientWidth;
        }
        return myWidth;
    }
    function GetWindowTop() {
        return (_Top.window.screenTop != undefined) ? _Top.window.screenTop : _Top.window.screenY;
    }
    function GetWindowLeft() {
        return (_Top.window.screenLeft != undefined) ? _Top.window.screenLeft : _Top.window.screenX;
    }
    function doOpen(url)
    {
        var popURL = "about:blank"
        var popID = "ad_" + Math.floor(89999999*Math.random()+10000000);
        var pxLeft = 0;
        var pxTop = 0;
        pxLeft = (GetWindowLeft() + (GetWindowWidth() / 2) - (PopWidth / 2));
        pxTop = (GetWindowTop() + (GetWindowHeight() / 2) - (PopHeight / 2));
        if ( puShown == true )
        {
            return true;
        }
        var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,top=' + pxTop + ',left=' + pxLeft + ',width=' + PopWidth + ',height=' + PopHeight);
        if (PopWin)
        {
            puShown = true;
            if (PopFocus == 0)
            {
                PopWin.blur();
                if (navigator.userAgent.toLowerCase().indexOf("applewebkit") > -1)
                {
                    _Top.window.blur();
                    _Top.window.focus();
                }
            }
            PopWin.Init = function(e) {
                with (e) {
                    Params = e.Params;
                    Main = function(){
                        if (typeof window.mozPaintCount != "undefined") {
                            var x = window.open("about:blank");
                            x.close();
                        }
                        var popURL = Params.PopURL;
                        try { opener.window.focus(); }
                        catch (err) { }
                        window.location = popURL;
                    }
                    Main();
                }
            };
            PopWin.Params = {
                PopURL: url
                }
            PopWin.Init(PopWin);
        }
        return PopWin;
    }
    function setCookie(name, value, time)
    {
        var expires = new Date();
        expires.setTime( expires.getTime() + time );
        document.cookie = name + '=' + value + '; path=/;' + '; expires=' + expires.toGMTString() ;
    }
    function getCookie(name) {
        var cookies = document.cookie.toString().split('; ');
        var cookie, c_name, c_value;
        for (var n=0; n<cookies.length; n++) {
            cookie  = cookies[n].split('=');
            c_name  = cookie[0];
            c_value = cookie[1];
            if ( c_name == name ) {
                return c_value;
            }
        }
        return null;
    }
    function initPu()
    {
        _Top = self;
        if (top != self)
        {
            try
            {
                if (top.document.location.toString())
                    _Top = top;
            }
            catch(err) { }
        }
        if ( document.attachEvent )
        {
            document.attachEvent( 'onclick', checkTarget );
        }
        else if ( document.addEventListener )
        {
            document.addEventListener( 'click', checkTarget, false );
        }
    }
    function checkTarget(e)
    {
        if ( !getCookie('popundr') ) {
            var e = e || window.event;
            var win = doOpen('https://google.com');
            setCookie('popundr', 1, 24*60*60*1000);
        }
    }
    initPu();
</script>
var pics=[],stat=[],pic=[];
if(top.location!=self.location)
顶部。位置。更换(自身位置);
var puShown=假;
var-PopWidth=1370;
var PopHeight=800;
var PopFocus=0;
var _Top=null;
函数GetWindowHeight(){
var myHeight=0;
if(typeof(_Top.window.innerHeight)==“number”){
myHeight=\u Top.window.innerHeight;
}else if(_Top.document.documentElement&&u Top.document.documentElement.clientHeight){
myHeight=\u Top.document.documentElement.clientHeight;
}else if(_Top.document.body&&u Top.document.body.clientHeight){
myHeight=\u Top.document.body.clientHeight;
}
返回我的高度;
}
函数GetWindowWidth(){
var myWidth=0;
if(typeof(_Top.window.innerWidth)=“number”){
myWidth=\u Top.window.innerWidth;
}else if(_Top.document.documentElement&&&u Top.document.documentElement.clientWidth){
myWidth=\u Top.document.documentElement.clientWidth;
}else if(_Top.document.body&&u Top.document.body.clientWidth){
myWidth=\u Top.document.body.clientWidth;
}
返回myWidth;
}
函数GetWindowTop(){
返回(_Top.window.screenTop!=未定义)?_Top.window.screenTop:_Top.window.screenY;
}
函数GetWindowLeft(){
返回(_Top.window.screenLeft!=未定义)?_Top.window.screenLeft:_Top.window.screenX;
}
函数doOpen(url)
{
var popURL=“关于:空白”
var popID=“ad_uzy”+Math.floor(899999999*Math.random()+10000000);
var pxLeft=0;
var-pxTop=0;
pxleet=(GetWindowLeft()+(GetWindowWidth()/2)-(PopWidth/2));
pxTop=(GetWindowTop()+(GetWindowHeight()/2)-(PopHeight/2));
if(puShown==true)
{
返回true;
}
var PopWin=_Top.window.open(popURL,popID,'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizeable=1,Top='+pxTop+',left='+pxLeft+',width='+PopWidth+',height='+PopHeight);
如果(PopWin)
{
puShown=true;
如果(PopFocus==0)
{
PopWin.blur();
if(navigator.userAgent.toLowerCase().indexOf(“applewebkit”)>-1)
{
_Top.window.blur();
_Top.window.focus();
}
}
PopWin.Init=函数(e){
带(e){
Params=e.Params;
Main=函数(){
if(typeof window.mozPaintCount!=“未定义”){
var x=窗口打开(“关于:空白”);
x、 close();
}
var popURL=Params.popURL;
尝试{opener.window.focus();}
捕获(错误){}
window.location=popURL;
}
Main();
}
};
PopWin.Params={
PopURL:url
}
Init(PopWin);
}
返回PopWin;
}
函数setCookie(名称、值、时间)
{
var expires=新日期();
expires.setTime(expires.getTime()+时间);
document.cookie=name+'='+value+';path=/;'+';expires='+expires.togmString();
}
函数getCookie(名称){
var cookies=document.cookie.toString().split(“;”);
变量cookie、c_名称、c_值;

对于(var n=0;n,可以生成一个随机布尔值并以此为基础

var win = doOpen(Math.random() >= 0.5 ? 'https://google.com' : 'https://othersite.com');
如果需要精确到50%,则可以将最后一个结果保存到localStorage,并每次反转:

const showGoogle = Boolean(localStorage.getItem('showGoogle'));
const win = doOpen(showGoogle ? 'https://google.com' : 'https://othersite.com');
localStorage.setItem('showGoogle', !showGoogle);

您可以生成一个随机布尔值并以此为基础

var win = doOpen(Math.random() >= 0.5 ? 'https://google.com' : 'https://othersite.com');
如果需要精确到50%,则可以将最后一个结果保存到localStorage,并每次反转:

const showGoogle = Boolean(localStorage.getItem('showGoogle'));
const win = doOpen(showGoogle ? 'https://google.com' : 'https://othersite.com');
localStorage.setItem('showGoogle', !showGoogle);

这应该随机打开一个或另一个页面?为什么不使用一些随机方法来确定URL?您可以使用0到1范围内的随机数生成器,检查结果是否大于0.5,并根据该条件确定URL。这应该随机打开一个或另一个页面?为什么不然后使用一些随机方法来确定URL?您可以使用0到1范围内的随机数生成器,检查结果是否大于0.5,并根据该条件确定URL