Tag: window.location

设置JavaScript window.location

我目前正在设置window.location.pathname属性redirect用户到一个相对的URL。 新的URL有参数,所以JavaScript的行看起来像这样: window.location.pathname = window.location.pathname.substring( 0, window.location.pathname.lastIndexOf( '/' ) + 1 ) + 'myPage.xhtml?u=' + selected_user.Username; 这在Firefox中是成功的,但Chrome使用'%3F'对问号进行编码,然后请求失败。 我不确定是否正确使用window.location。 我是否需要使用window.location的属性,如path名或href? 我发现,只要我设置一个属性的位置重新加载,所以例如,search和path名属性不能单独设置。 可以直接设置window.location吗? 我只需要用参数设置一个相对的URL。

更改哈希,而无需在jQuery中重新加载

我有以下代码: $('ul.questions li a').click(function(event) { $('.tab').hide(); $($(this).attr('href')).fadeIn('slow'); event.preventDefault(); window.location.hash = $(this).attr('href'); }); 这只是简单地淡化你点击时的div,但是当你点击的时候,我希望页面的URL哈希标签改变,以便人们可以复制和书签。 目前,当散列标签发生变化时,这将有效地重新加载页面。 是否有可能改变哈希标签,而不是重新加载页面,以防止跳跃效应?

我怎样才能使一个HTML超链接href使用window.location打开一个新的窗口?

这是我的代码: <a href="http://www.google.com" onClick="window.location.href='http://www.yahoo.com';return false;" target="_blank">test</a> 当你点击它,它会把你带到雅虎,但它不会打开一个新的窗口?

window.location与只是位置

在整个networking中,我看到大量的JavaScript程序员编写window.location而不是location 。 我很好奇,如果有人能够提供一个解释,为什么。 window是全局对象,因此没有必要包含 – 不是吗? 我的意思是,你没有看到人写new window.Date()或new window.Date() ,所以我很好奇,为什么它将与location指定。 我明白, location被认为是你所在的窗户的“财产”,我认为这是有道理的。 但即便如此,我也没有看到任何理由来指定全局对象。 首先不可能覆盖location ,而不是不redirect页面。 那么,这只是一个已经被使用了很长时间的怪癖,它已经和我们写JavaScript的方法结合起来了,还是有一些这样做的有形的理由? 我检查了谷歌,但唉,我什么都没有想出来…

IE11 – 对象不支持属性或方法'包括' – javascript的window.location.hash

我正在检查url,看看它是否包含或包含? 在其中控制窗口中的哈希popup状态。 所有其他浏览器只有IE没有问题。 debugging器给我这个错误,当我尝试以这种方式加载对象不支持属性或方法“包括” 当我通过popstate加载页面时,我没有得到任何错误 $(document).ready(function(e) { if(window.location.hash) { var hash; if(window.location.hash.includes("?")) { alert('I have a ?'); hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?')); }else { hash = window.location.hash; }; if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){ $(hash+'Content').addClass('pageOn').removeClass('pageOff'); }else { $('#homeContent').addClass('pageOn').removeClass('pageOff'); }; } else { $('#homeContent').addClass('pageOn').removeClass('pageOff'); […]

window.location.assign()和window.location.replace()之间的区别

window.location.assign()和window.location.replace()之间有什么区别,当redirect到一个新的页面?

当前页面的JavaScript硬刷新

我如何强制网页浏览器通过JavaScript对页面进行硬刷新? 硬刷新意味着获取页面的全新副本并刷新所有外部资源(图像,JavaScript,CSS等)。

检测HTTP或HTTPS,然后在JavaScript中强制使用HTTPS

有没有什么办法来检测HTTP或HTTPS,然后用JavaScript强制使用HTTPS? 我有一些代码检测HTTP或HTTPS,但我不能强迫它使用https: 我正在使用window.location.protocol属性来设置网站是https:然后刷新页面,希望重新加载一个新的https'ed URL加载到浏览器。 if (window.location.protocol != "https:") { window.location.protocol = "https:"; window.location.reload(); }

PhoneGap for iPhone:加载外部URL时出现问题

我正在使用PhoneGap为iPad编写应用程序,我希望加载外部URL而不触发Safari或使用内部networking浏览器(如ChildBrowser)。 我正在使用PhoneGap iPad / iPhone示例项目,并尝试了不同的方法。 在onBodyLoad()函数中我添加了: window.location.href('http://www.wordreference.com'); 但这一行使用新的Safari窗口打开链接。从这一点是不可能回到PhoneGap 之后,我尝试使用document.writereplace页面内容的AJAX请求 function loadHTML(url, timeout) { if (timeout == undefined) timeout = 10000; var req = new XMLHttpRequest(); var timer = setTimeout(function() { try { req.abort(); } catch(e) {} navigator.notification.loadingStop(); },timeout); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status < 300) { clearTimeout(timer); var html […]

在JavaScript中的window.location和document.location之间有什么区别?

他们是否应该引用同一个对象?