Getting current URL using Jquery

I am very new in javascript and jquery.

$.getJSON("idcheck.php?callback=?", { url:  /*i want full url to be print*/ }, function(json){
  //alert(json.message);
});

How do i get current full url on page on after url: in above?

Thank you


This will give you the current url:

window.location.pathname

edit:

$.getJSON("idcheck.php?callback=?", { url:  window.location.pathname }, function(json){
  //alert(json.message);
});

edit 2: Using PHP (found via)

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>


$.getJSON("idcheck.php?callback=?", { url:  "<?php echo curPageURL(); ?>" }, function(json){
  //alert(json.message);
});

你应该使用window.location.pathnamewindow.location


通过Jquery和Javascript获取当前页面的URL

  $(document).ready(function() {
      //jquery
    $(location).attr('href');

    //pure javascript
    var pathname = window.location.pathname;

    // to show it in an alert window
    alert(window.location);
});


$.getJSON("idcheck.php?callback=?", { url:$(location).attr('href')}, function(json){
  //alert(json.message);
});
链接地址: http://www.djcxy.com/p/70244.html

上一篇: 使用jQuery来获取网址并提取网址段

下一篇: 使用Jquery获取当前的URL