Ich bin sehr neu in Javascript und Jquery.Erhalten der aktuellen URL mit Jquery
Wie bekomme ich aktuelle volle URL auf Seite auf nach URL: in oben?
Danke
Ich bin sehr neu in Javascript und Jquery.Erhalten der aktuellen URL mit Jquery
Wie bekomme ich aktuelle volle URL auf Seite auf nach URL: in oben?
Danke
Dies gibt Ihnen die aktuelle URL:
window.location.pathname
edit:
$.getJSON("idcheck.php?callback=?", { url: window.location.pathname }, function(json){
//alert(json.message);
});
bearbeiten 2: Verwendung von PHP (gefunden 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);
});
Wie implementiere ich es? Derzeit, wenn ich dies stelle, zeigt es nur als window.location.pathname; –
Ich habe meine Nachricht bearbeitet, es sollte funktionieren – marcgg
es zeigt als URL: window.location.Pfadname, nicht die aktuelle URL davon, ich brauche etwas wie URL: localhost/index.html –
Du solltest verwenden window.location.pathname
oder window.location
Zur aktuellen Seite URL via JQuery und Javascript
$(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);
});
Sie können diese erhalten verwenden:
var path = window.location.pathname; // path only
var url = window.location.href; // full URL
Edit:
$.getJSON("idcheck.php?callback=?", { url: window.location.href }, function(json){ alert(json.message);});
Ich denke, dies ist ein Duplikat von http://stackoverflow.com/questions/406192/how-to-extract-current-url-in-jquery. –
Ich habe es schon gesehen, aber ich weiß nicht, wie ich es in meinem Kontext implementieren soll, also wäre jede Hilfe dankbar –