Javascript current url
Javascript current url
我使用的是javascript。如何获取当前URL的路径并将其分配给我的代码?这是我的代码:
$(document).ready(function() {
$(".share").hideshare({
link: "current_url",
position: "top"
});
});
尝试window.location.href
$(document).ready(function() {
$(".share").hideshare({
link: window.location.href,
position: "top"
});
});
尝试使用window.location.href
或document.URL
对象
$(document).ready(function() {
$(".share").hideshare({
link: window.location.href,
position: "top"
});
});
应该使用以下方法:
$(document).ready(function() {
$(".share").hideshare({
link: location.href
position: "top"
});
});
window.location(也可以被location
引用)属性包含许多与当前页面相关的实用程序函数。
例如锚的window.location.hash
或查询字符串的window.location.search
如果不需要完整的url,则可以使用window.location.href
或window.location.path
表达式。
如果不需要完整的url,请使用window.location.href
或window.location.pathname
表达式。我是说
$(document).ready(function() {
$(".share").hideshare({
link: "window.location.href/window.location.pathname",
position: "top"
});
});
要获取当前URL,可以使用:
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 使用php或javascript从facebook相册URL中删除多余的部分
- Angular JS IE9 Hashbang url rewriting
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 直接下载文件,而不是从window.open(url)
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 通过js在新选项卡中有条件地打开url
- CKFinder 3为所选文件返回错误的URL
- 如何获取不属于我项目的上一页的URL
- ReactJS映射:如何仅在url变量不为空时呈现html链接
- 在URL中传递JS对象
- 将纯文本URL转换为可单击链接
- Javascript html每点击一次就会更改url
- 以角度管理动态URL
- Mathias URL shortener
- 如何有效地将游戏数据存储在URL查询字符串中
- 使用带括号的图像URL作为jQuery的背景
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- Javascript current url
- HttpContext.Current.Request.Url.Host and window.location.hos