Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.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 jquery在开发站点工作,但不在生产站点window.location工作_Javascript_Jquery - Fatal编程技术网

Javascript jquery在开发站点工作,但不在生产站点window.location工作

Javascript jquery在开发站点工作,但不在生产站点window.location工作,javascript,jquery,Javascript,Jquery,我有一个简单的脚本,确定我们是否在基本URL,并根据位置加载不同的内容。条件在开发和生产中都匹配,但在生产中它没有满足条件吗 <script type="text/javascript"> $(document).ready(function() { var myurl = '<!-- TMPL_VAR base_url -->'; /*returns http://instance_name.dev.domain.com/ */ var currentu

我有一个简单的脚本,确定我们是否在基本URL,并根据位置加载不同的内容。条件在开发和生产中都匹配,但在生产中它没有满足条件吗

<script type="text/javascript">
$(document).ready(function() {
    var myurl = '<!-- TMPL_VAR base_url -->'; /*returns http://instance_name.dev.domain.com/ */
    var currenturl = window.location; 
    alert(currenturl); /*returns http://instance_name.dev.domain.com/ */
    if(myurl == currenturl) {
        $( "#logo" ).load( "/static/carousel.html" );
    }
    else {
        $( "#logo" ).append( '<div class="logo visible-desktop visible-tablet"><img src="/static/images/logo.png" alt="A.A. Green Realty, Inc." /><h3>Real Estate | Real Experts | Real Results</h3></div>' );
    }    
});
</script>

$(文档).ready(函数(){
var myurl='';/*返回http://instance_name.dev.domain.com/ */
var currenturl=window.location;
警报(当前URL);/*返回http://instance_name.dev.domain.com/ */
如果(myurl==currenturl){
$(“#logo”).load(“/static/carousel.html”);
}
否则{
$(“#logo”).append('Real Estate | Real Experts | Real Results');
}    
});
控制台输出:

> http://terricookson.dev.activemls.com/
> terricookson.dev.activemls.com/:893 LocationancestorOrigins:
> DOMStringListassign: function () { [native code] }hash: ""host:
> "terricookson.dev.activemls.com"hostname:
> "terricookson.dev.activemls.com"href:
> "http://terricookson.dev.activemls.com/"origin:
> "http://terricookson.dev.activemls.com"pathname: "/"port: ""protocol:
> "http:"reload: function reload() { [native code] }arguments:
> nullcaller: nulllength: 0name: "reload"__proto__: function Empty()
> {}apply: function apply() { [native code] }arguments: nullbind:
> function bind() { [native code] }call: function call() { [native code]
> }caller: nullconstructor: function Function() { [native code] }length:
> 0name: "Empty"toString: function toString() { [native code]
> }__proto__: Object<function scope><function scope>replace: function ()
> { [native code] }search: ""toString: function toString() { [native
> code] }valueOf: function valueOf() { [native code] }__proto__:
> Location
>http://terricookson.dev.activemls.com/
>terricookson.dev.activemls.com/:893 LocationancestorOrigins:
>DOMStringListassign:函数(){[本机代码]}哈希:“”主机:
>“terricookson.dev.activemls.com”主机名:
>“terricookson.dev.activemls.com”href:
> "http://terricookson.dev.activemls.com/“来源:
> "http://terricookson.dev.activemls.com路径名:“/”端口:“”协议:
>“http:”重新加载:函数重新加载(){[本机代码]}参数:
>nullcaller:nulllength:0name:“重新加载”\u uu协议\u uuu:函数为空()
>{}apply:function apply(){[native code]}参数:nullbind:
>函数bind(){[native code]}调用:函数调用(){[native code]
>}调用方:nullconstructor:function(){[本机代码]}长度:
>0name:“Empty”toString:函数toString(){[本机代码]
>}\uuuu proto\uuuu:Objectreplace:function()
>{[native code]}搜索:“toString:函数toString(){[native]
>code]}valueOf:函数valueOf(){[本机代码]}\uuuuuuuuuuuuuuuuuuuuuuuu:
>位置

您可以使用此选项

window.location.pathname === "/"

他们真的匹配吗<代码>控制台日志(escape(myurl));log(escape(currenturl))我打赌它就像是结尾的一个空格,或者是大小写的不同之处。@epascarello我将控制台输出添加到了我的opdos
TMPL\u VAR base\u url
匹配这两种环境?如果您这样告诉我们渲染的源代码,它会更有用。您的控制台日志记录在哪里进行?添加一个控制台日志很好,但是在不了解日志记录位置的情况下也可以。对于那些投票反对的人,你能解释一下原因吗?