【问题标题】:How to get the current url of html page using phonegap如何使用phonegap获取html页面的当前url
【发布时间】:2013-10-27 09:04:59
【问题描述】:

我正在使用 jquery、jquery mobile 和 html 使用 phonegap 构建移动应用程序,我的 index.html 显示名称列表

 <li><a href="profile.html?id='+item.id+'"><h3>'+item.fname+' '+item.lname+'</h3></a></li> 

当用户点击列表中的任何人时,应显示该人的个人资料, 我需要获取当前的 url (profile.html?id=) 来提取人的 id 来进行数据库查询。

我尝试使用(在 profile.html 的正文中)

<script> 
 url=window.location.href;
<script> 

   <script>
    url=document.URL;
    </script>

但两者都返回 index.html 的 url 而不是第二页 (profile.html?id=),即使当我在浏览器上测试时页面的 URL 更改为 profile.html?id=2 有什么想法?

【问题讨论】:

  • @Vicky Gonsalves 谢谢,实际上我的问题不是如何获取 url 查询值,而是要获取当前 url 这样做(调试显示上一页 url)。好吧,问题已随解决方案更新。
  • 您可以将该解决方案添加为下面的答案并接受它,以便将此问题标记为已回答。
  • @Purus 完成谢谢。

标签: javascript php jquery html cordova


【解决方案1】:

经过多次尝试和搜索,找到了解决方案,使用

$.mobile.activePage[0].baseURI;

根据 Alex Bachuk 的说法,使用 window.location.href 会返回上一页 URL,而活动页面通过 AJAX 插入到 DOM 中,我们需要使用 mobile.activePage[0] 来获取当前页面 URL。

来源:http://alexbachuk.com/jquery-mobile-active-page-url/

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 2012-03-02
    • 1970-01-01
    相关资源
    最近更新 更多