[英]Replace URL in address bar with a subdomain withOUT redirecting
I have total control over my entire domain and its subdomains, and I want to replace the URL displayed in the address bar with a subdomain but not redirect the page. 我对整个域及其子域拥有完全控制权,我想用子域替换地址栏中显示的URL,但不重定向页面。
For example, when I load subdomain.mydomain.com?register
I want the address bar to display register.mydomain.com
without redirecting. 例如,当我加载
subdomain.mydomain.com?register
我希望地址栏显示 register.mydomain.com
而不进行重定向。
ALL pages and subdomains of mydomain.com
already have document.domain = 'mydomain.com';
mydomain.com
所有页面和子域都已经具有document.domain = 'mydomain.com';
as the first thing in the $(window).load(function () {
code of its external .js
file. 作为
$(window).load(function () {
其外部.js
文件的代码中的第一件事。
I've tried history.pushState("", "", '/');
我已经尝试过
history.pushState("", "", '/');
to strip away anything after the subdomain.mydomain.com
(which works), and I've been able to display something after the /
(which also works), but I can't get the displayed subdomain to change before the /
. 删除
subdomain.mydomain.com
(有效)之后的任何内容,并且我已经能够在/
之后显示内容(也可以工作),但无法在/
之前更改显示的子域。
How do I do this? 我该怎么做呢? Is it possible at all?
有可能吗? If so, does it rely on
document.domain
? 如果是这样,它是否依赖
document.domain
? And if it does, am I executing document.domain
properly?? 如果可以,我是否可以正确执行
document.domain
?
Should I put 我应该放
<script type="text/javascript">
document.domain = 'mydomain.com';
</script>
by itself in the <head>
of my HTML files, or will it work just fine being in the $(window).load(function () {
code of its external .js
file? 单独放在我的HTML文件的
<head>
中,还是放在外部.js
文件的$(window).load(function () {
代码中?
I'm not sure about domain/subdomain things, but I have a page where a user can click multiple items and depending on his/her input, a URL that is displayed in browser's address bar changes. 我不确定域/子域的问题,但是我有一个页面,用户可以单击多个项目,并且根据他/她的输入,浏览器地址栏中显示的URL会更改。 There is how I do it without redirecting:
我有没有重定向的方法:
var newurl = window.location.protocol
+ "//" + window.location.host + window.location.pathname
+ StrippedQueryString + '&H=' + Parameter;
if (history.replaceState) {
window.history.replaceState({ path: newurl }, '', newurl);
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.