草庐IT

ref_location

全部标签

Javascript:获取 window.location 除主机外的所有内容?

我喜欢http://www.mydomain.com/hello/you使用top.location.host,我可以获得"http://www.mydomain.com"使用window.location.href我可以得到"http://www.mydomain.com/hello/you"有没有机会得到"/hello/you"??? 最佳答案 location.pathnamepathname将仅返回路径。如果您需要querystring和可选的hash,您还需要组合search和hash属性。考虑这个网址:http://ww

javascript - 当 window.location=self.location 不起作用时通过 AJAX 重新加载页面

在我的主页上我得到:log-in|sign-up通过MooTools,我通过id获取这些anchor元素,这样一旦它们被点击,一个华丽的div就会在它们下面弹出,其中包含登录或注册表单(当然还有停止事件传播的方法)并在填写字段后启动AJAX调用-这应该创建一个session并重新加载页面,以便用户可以看到他现在已登录并且出现用户级控件等。ajax调用由MooToolsAJAX类发起,evalScripts选项设置为true。AJAX页面返回脚本代码:window.location=self.location;这个系统运行完美-现在我想知道为什么如果我将anchor的href值更改为hr

javascript - 渲染后获取 React.refs DOM 节点宽度,仅当宽度值发生变化时才触发重新渲染

我正在尝试获取refDOM元素的宽度并设置state,然后在组件render中使用。问题来了,因为这个宽度在用户输入时发生变化,当我在componentDidUpdate中尝试setState时,它开始无限循环,我的浏览器崩溃了。我在这里创建了一个fiddlehttp://jsbin.com/dizomohaso/1/edit?js,output(打开控制台获取一些信息)我的想法是;组件安装,setState:refs.element.clientWidth用户输入数据,触发rendershouldComponentUpdate仅当new.state不等于old时才返回true.状态。

javascript - XML 解析错误 : no root element found Location in Console FF

我使用的是ASP.NETMVC,但我只在FF中遇到这个错误。为什么我会收到此错误消息?这是什么原因?我不明白这个错误的根源在哪里。有人有什么想法吗?下一个错误: 最佳答案 检查这个link了解更多信息Basedonmyresearch,theerrormessageisonlygeneratedbyFireFoxwhentherenderpageisblankinInternet.Forsomereason,.NETgeneratesaresponsetypeof"application/xml"whenitcreatesanemp

javascript - 使用 React refs 的 scrollIntoView

当用户关闭另一个组件时,我们试图滚动到特定组件。我们的示例与下面的示例非常相似,摘自https://reactjs.org/docs/refs-and-the-dom.html#exposing-dom-refs-to-parent-componentsfunctionCustomComponents(props){constitems=[1,2,3,4].map((x,i)=>return(x+hello)return({items});}functionParent(props){return();}classGrandparentextendsReact.Component{re

javascript - JavaScript location.href 调用是异步的吗?

functionfun(){console.log("Hi");window.location.href="http://www.google.com";console.log("Hello,howareyou");alert("Iamgood");fun1();}functionfun1(){console.log("Whatsup??");}在上面的代码行中,之前调用了location.hrefconsole.log("Hello,howareyou")、alert和fun1()。当我调用fun()时,它会执行location.href下面的所有语句,然后重定向到https://w

javascript - 将标题添加到 window.location.pathname

我正在为应用程序设置身份验证。在我发出登录后请求后,将发送一个JSONWebtoken作为响应。我可以通过Ajax将其附加到header。问题是在登录后使用window.location.pathname重定向时,因为它不是Ajax请求,所以它没有附加到header的token。我该如何解决这个问题?$.ajaxSetup({headers:{'x-access-token':window.localStorage.jwt}});varAuth={signup:function(){console.log('signuppp');varuserSignup={username:$('#

javascript - React refs 不会在渲染之间更新

所以我有这个组件varLineItemRowsWrapper=React.createClass({current_lineitem_count:0,getAjaxData:function(){varlineitem_data=[];for(vari=0;i)});}returnlineitem_components;},render:function(){varlineitems=this.getLineitems();return({lineitems})}})第一次呈现lineitems时,refs会按预期工作。但是,如果我向this.props.shoot添加一个lineit

javascript - 为什么在使用相同的 location.href(或空)推送时 window.onpopstate 上的 event.state 为空

在不更改URL的情况下推送到历史记录并设置数据时:window.history.pushState({stateName:"myStateName",randomData:window.Math.random()},"myStateName",location.href);....然后监听弹出事件并通过按下浏览器中的返回按钮触发它:window.onpopstate=function(event){console.log(event.state);//logsnull}大多数时候你会得到null作为状态值而不是:{stateName:"myStateName",randomData:0

javascript - 是否可以用自定义函数覆盖 window.location 函数?

是否可以禁用或更好地替换为自定义函数window.location?这个问题是相关的:Disableabuilt-infunctioninjavascript(alert)虽然它适用于window.alert,但不适用于window.location。我们希望能够找到一种方法来替换或禁用(替换将是理想的,这样我们就可以使用AJAX记录)window.location...肮脏的广告商有时会使用它从我们的网络属性(property)中窃取人们。有什么想法吗?即使是只适用于少数特定浏览器的东西也可以,因为一旦被捕获(通过AJAX日志记录)我们就可以相当快地对此采取行动。