3

ページをリロードせずにブラウザ バーの URL を変更したい。

<html><head>
 <title>Change url in browser bar</title>
</head>
     <body>
             <h1>Refresh page to see our other website</h1>
     </body>
 </html>

ユーザーがwww.a-site.comのような私の Web サイトにアクセスすると、このサイトを開いた後、 「ページを更新して他の Web サイトを表示する」というテキスト が表示されます。彼がwww.a-site.comに入力したときに、この URL がwww.b-site.comのようなブラウザ バーで変更された後、ユーザーがページを更新すると、自動的に
www.b-site.comにリダイレクトできますか。これは可能ですか。
ありがとう...............

4

1 に答える 1

11

次を探しています

window.history.pushState("object or string", "Title", "/new-url");

私が読んだ元の記事 (2012 年 7 月 10 日投稿) は次のとおりです。

例:

 function processAjaxData(response, urlPath){
     document.getElementById("content").innerHTML = response.html;
     document.title = response.pageTitle;
     window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath);
 }

ドキュメンテーション

于 2013-10-05T02:39:47.393 に答える