我想拿个字符串
var a = "http://example.com/aa/bb/"
Run Code Online (Sandbox Code Playgroud)
并将其处理成一个对象
a.hostname == "example.com"
Run Code Online (Sandbox Code Playgroud)
和
a.pathname == "/aa/bb"
Run Code Online (Sandbox Code Playgroud) 我怎么能做这样的事情:
<script type="text/javascript">
$(document).ready(function () {
if(window.location.contains("franky")) // This doesn't work, any suggestions?
{
alert("your url contains the name franky");
}
});
</script>
Run Code Online (Sandbox Code Playgroud) 我有一个问题:我想通过JavaScript重定向到上面的目录.我的代码:
location.href = (location.href).substr(0, (location.href).lastIndexOf('folder'));
Run Code Online (Sandbox Code Playgroud)
网址如下所示:
example.com/path/folder/index.php?file=abc&test=123&lol=cool
重定向会影响到这个:
example.com/path/&test=123&lol=cool
但想拥有这个:
example.com/path/
我怎么能这样做?
你如何在Android中编码URL?
我以为是这样的:
final String encodedURL = URLEncoder.encode(urlAsString, "UTF-8");
URL url = new URL(encodedURL);
Run Code Online (Sandbox Code Playgroud)
如果我执行上述操作,则将http://in urlAsString替换为http%3A%2F%2Fin encodedURL,然后java.net.MalformedURLException在使用URL时获取 .
我正在访问我的网站上的链接,每次访问时都会提供一个新图像.
我遇到的问题是,如果我尝试在后台加载图像然后更新页面上的图像,图像不会改变 - 虽然它在我重新加载页面时更新.
var newImage = new Image();
newImage.src = "http://localhost/image.jpg";
function updateImage()
{
if(newImage.complete) {
document.getElementById("theText").src = newImage.src;
newImage = new Image();
number++;
newImage.src = "http://localhost/image/id/image.jpg?time=" + new Date();
}
setTimeout(updateImage, 1000);
}
Run Code Online (Sandbox Code Playgroud)
FireFox看到它们的标题:
HTTP/1.x 200 OK
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: image/jpeg
Expires: Fri, 30 Oct 1998 14:19:41 GMT
Server: Microsoft-HTTPAPI/1.0
Date: Thu, 02 Jul 2009 23:06:04 GMT
Run Code Online (Sandbox Code Playgroud)
我需要在页面上强制刷新该图像.有任何想法吗?
从URL查询字符串获取参数的"需要更少代码"的方法是什么,格式如下?
www.mysite.com/category/subcategory?myqueryhash
输出应该是: myqueryhash
我知道这种方法:
www.mysite.com/category/subcategory?q=myquery
<?php
echo $_GET['q']; //Output: myquery
?>
Run Code Online (Sandbox Code Playgroud) 如果我在HTML页面中有一个非滚动标题,则固定在顶部,具有已定义的高度:
有没有办法使用URL锚点(#fragment部分)让浏览器滚动到页面中的某个点,但是在没有JavaScript帮助的情况下仍然尊重固定元素的高度?
http://foo.com/#bar
Run Code Online (Sandbox Code Playgroud)
WRONG (but the common behavior): CORRECT: +---------------------------------+ +---------------------------------+ | BAR///////////////////// header | | //////////////////////// header | +---------------------------------+ +---------------------------------+ | Here is the rest of the Text | | BAR | | ... | | | | ... | | Here is the rest of the Text | | ... | | ... | +---------------------------------+ +---------------------------------+
我正在寻找一个可以获取URL参数的jQuery插件,并支持此搜索字符串而不输出JavaScript错误:"格式错误的URI序列".如果没有支持这个的jQuery插件,我需要知道如何修改它来支持这个.
?search=%E6%F8%E5
Run Code Online (Sandbox Code Playgroud)
解码后,URL参数的值应为:
æøå
Run Code Online (Sandbox Code Playgroud)
(字符是挪威语).
我无权访问服务器,因此我无法对其进行任何修改.
我如何使用可能对当前页面产生一些影响的JavaScript操作,但也会更改浏览器中的URL,以便在用户点击重新加载或书签时使用新URL?
如果后退按钮会重新加载原始URL也会很好.
我试图在URL中记录JavaScript状态.
我想对URL进行编码:
SELECT name FROM user WHERE uid = me()
Run Code Online (Sandbox Code Playgroud)
我必须为此下载模块吗?我已经有了请求模块.
url ×10
javascript ×7
query-string ×2
anchor ×1
android ×1
fragment ×1
hashchange ×1
html ×1
image ×1
jquery ×1
node.js ×1
php ×1
redirect ×1
refresh ×1
urlencode ×1