Please don't mark this as a duplicate. I have tried all the methods suggested on StackOverflow and none of them work. They all give me the URL of the referring page, not the current page. Or they don't work at all. Even window.location.href returns the referring page URL, not the current page URL. I'm using jQuery Mobile 1.4.5.
For example say I was on page1.php and I clicked a link to page1.php?getvar=42. Page 1 looks like this:
<!doctype html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
</head>
<body><div data-role="page" data-dom-cache="false">
<a href="page1.php?getvar=42">Click Here</a>
<?php if ($_GET['getvar']=='42'): ?>
<script>
console.log(window.location.href);
console.log(document.location.href);
console.log($.mobile.activePage.data('url'));
</script>
<?php endif ?>
</div></body></html>
When I click the link in the above page and I look at what it says in the console. I get:
http://hostname/page1.php
http://hostname/page1.php
/page1.php
I've also tried wrapping these calls to console.log() in a jQuery $(document).ready() function with no change in the result.
<script>
$(function() {
console.log(window.location.href);
console.log(document.location.href);
console.log($.mobile.activePage.data('url'));
});
</script>
As you can see none of these are the complete URL. The same is true when linking to a different file. So it doesn't just affect pages with GET variables on the URL. I am expecting to see /page1.php?getvar=42
I've found topics on Stack Overflow that ask this same question but none of the answers are working for me. Perhaps they are using a different version of jQuery Mobile. I'm using jQuery 1.4.5 as you can see.
So far the only solution that I have found is to turn off ajax loading of pages in jQuery mobile by putting data-ajax="false" on a parent container. But there must be a better way.
(By the way, the reason I need this is so that I can reload the current page. But currently all attempts to reload the current page just take me back to the referring page. And this is why.)