【问题标题】:facebox opened page get querystringfacebox打开页面获取查询字符串
【发布时间】:2011-06-22 11:53:56
【问题描述】:

我在一个页面 mainpage.aspx" 中我有这个代码:
<a rel="facebox" href="destination.htm?path=blabla">mainpage</a>
我使用 facebox() 加载destination.htm
问题出在我的destination.htm 中,当我试图点击警报(window.location.href)时,我得到的是mainpage.aspx 而不是destination.htm.why?我要做的就是从页面中读取路径以获取查询字符串(但我得到了错误的路径)。
非常感谢

【问题讨论】:

    标签: asp.net html query-string facebox


    【解决方案1】:

    这是因为 facebox 实际上并没有将浏览器重定向到该页面,而是通过 ajax 获取并将其注入同一页面上的 facebox div。

    您可以尝试获取锚点的 href 属性,可能类似于:

    var lastVisited = null;
    var lastVisitedQS = null;
    $("a[rel='facebox']").facebox()
              .click(function() {
                  lastVisited = this.href;
    
                  // you can extract the query string like this
                  var a = document.createElement('a');
                  a.href = lastVisited;
                  lastVisitedQS = a.search; // should give path=blabla
              });
    

    然后在你的destination.htm 做:

    alert(lastVisited);
    alert(lastVisitedQS);
    

    希望有帮助!

    【讨论】:

    • @Grace - 哎呀,代码有错误(我忘了声明a
    • 只有一件事:行 var lastVisited = null;必须取出来,不然就不行了。再次感谢。
    【解决方案2】:

    您可以使用 window.location.hostname 获取主机 URL,使用 window.location.pathname 获取虚拟目录+页面,使用 window.location.search 获取 URL 的查询字符串部分

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-19
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多