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

时间:2014-11-05 18:11:39

标签: javascript jquery

我有一个简单的脚本,用于确定我们是否位于基本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>

控制台输出:

> 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

1 个答案:

答案 0 :(得分:1)

你可以改用它。

window.location.pathname === "/"