繁体   English   中英

用OUT重定向将地址栏中的URL替换为子域

[英]Replace URL in address bar with a subdomain withOUT redirecting

我对整个域及其子域拥有完全控制权,我想用子域替换地址栏中显示的URL,但重定向页面。

例如,当我加载subdomain.mydomain.com?register我希望地址栏显示 register.mydomain.com 而不进行重定向。

mydomain.com所有页面和子域都已经具有document.domain = 'mydomain.com'; 作为$(window).load(function () {其外部.js文件的代码中的第一件事。

我已经尝试过history.pushState("", "", '/'); 删除subdomain.mydomain.com (有效)之后的任何内容,并且我已经能够在/ 之后显示内容(也可以工作),但无法在/ 之前更改显示的子域。

我该怎么做呢? 有可能吗? 如果是这样,它是否依赖document.domain 如果可以,我是否可以正确执行document.domain


我应该放

 <script type="text/javascript">
 document.domain = 'mydomain.com';
 </script>

单独放在我的HTML文件的<head>中,还是放在外部.js文件的$(window).load(function () {代码中?

我不确定域/子域的问题,但是我有一个页面,用户可以单击多个项目,并且根据他/她的输入,浏览器地址栏中显示的URL会更改。 我有没有重定向的方法:

var newurl = window.location.protocol 
    + "//" + window.location.host + window.location.pathname 
    + StrippedQueryString + '&H=' + Parameter;

if (history.replaceState) {
    window.history.replaceState({ path: newurl }, '', newurl);
}

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM