我如何将窗口的URL哈希替换为另一个响应? [英] How can I replace a window's URL hash with another response?
本文介绍了我如何将窗口的URL哈希替换为另一个响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用replace方法更改哈希URL(document.location.hash),但它不起作用。
$(function(){
var anchor = document.location.hash;
//这会返回字符串值,如'#categories'
$( 'span')。click(function(){
$(window).attr('url')。replace(anchor,'#food');
//尝试改变当前的url.hash'#categories'
//与另一个字符串,我在这里填写。
});
});
我不想更改/刷新页面,我只想替换网址而无任何回应。 p>
注意:我不想用href =#food解决方案来解决这个问题。
解决使用
位置
或 window.location
而不是文档 window.location.hash ='#地点
,因为后者是非标准的。餐饮';
这将用您为其设置的值替换网址的哈希。
I am trying to change a hashed URL (document.location.hash) with the replace method, but it doesn't work.
$(function(){
var anchor = document.location.hash;
//this returns me a string value like '#categories'
$('span').click(function(){
$(window).attr('url').replace(anchor,'#food');
//try to change current url.hash '#categories'
//with another string, I stucked here.
});
});
I dont want to change/refresh page, I just want to replace URL without any responses.
Note: I don't want to solve this with a href="#food" solution.
解决方案
Either use location
or window.location
instead of document.location
as the latter is a non-standard.
window.location.hash = '#food';
This will replace the URL's hash with the value you set for it.
这篇关于我如何将窗口的URL哈希替换为另一个响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文