没有附加的window.location.href [英] window.location.href without append

查看:124
本文介绍了没有附加的window.location.href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,请在www.page.com页面上说即时消息
当我做window.location.href =/my var/

结果是
www.page.com/my var/

字符串被追加,我不想要,我希望window.location.href仅是/my var/

我该怎么办?
非常感谢您的帮助:)

Hello, say im on page www.page.com
when i do window.location.href=/my var/

the result is
www.page.com/my var/

the string is appended, i dont want that, i want window.location.href to be /my var/ only

how can i do this?
your help is much appreciated :)

推荐答案

如果您输入:

If you put:

window.location.href = '/myValue'



它将追加.如果您说:



it will append. If you say:

window.location.href = 'http://myValue'


然后它将转到该页面,而不附加网址.


it will then go to that page and not append the url.


原理上如何运作?

您需要执行以下操作:
How could it work in principle?

You need to do this:
window.location = "http://www.CodeProject.com";



因此,如果要使用变量,则1)应该具有有效的变量名称,2)应该为其分配有效文字的值:



Accordingly, if you want to work with a variable, 1) it should have a valid variable name, 2) it should be assigned a value of a valid literal:

myLocation = "http://www.CodeProject.com";
window.location = myLocation;



—SA



—SA


这篇关于没有附加的window.location.href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆