私の問題はthisと多少似ています。しかし、私の実装は少し異なるので、私は新しい質問を作成しました。Google ChromeのJavascriptリダイレクトの問題
私は、戻るボタンを無効にするページがあります(多くのグーグルの後にスクリプトがあります)。このページの動作は、別の場所にリダイレクトされることです(ASP.NET MVCコントローラアクション)。アクションの完了に時間がかかるため、待機メッセージが表示されます。以下は、戻るボタンを無効にしてページをリダイレクトするために使用したスクリプトです。
<script type="text/javascript">
function changeHashOnLoad() {
window.location.href += "#";
setTimeout(changeHashAgain, 50);
}
function changeHashAgain() {
window.location.href += "1";
}
var storedHash = window.location.hash;
window.setInterval(function() {
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);
//do after all images have finished loading
$(window).load(function() {
changeHashOnLoad();
//show the wait message
$("#domWaitMessage").show();
//redirect to the new page/controller action
window.location.href = document.forms[0].action;
});
</script>
上記のコードは、IEとFirefoxでは動作しますが、Chromeでは動作しません。 Operaでは多くの画面がちらつきますが、リダイレクトはまだ機能しています。クロムでは、私のコントローラ内のアクションが呼び出され、処理が行われますが、処理が完了してもページはリダイレクトされません。皆さんのほとんどは、フロー/実装を変更する必要があると感じているかもしれませんが、私はこの問題に言及していないので、この流れに固執する必要があります。
Platform: ASP.NET MVC 2.0
jQuery Version: 1.4.1
Chrome Version: 16.0.912.63m
UPDATE:以下
シオマネキやクロームネットワーク]タブから取られたスクリーンショットです。
フィドラー:
Fiddler Screenshot http://img43.imageshack.us/img43/638/200response.png
クローム:
Chrome Screenshot http://img594.imageshack.us/img594/6381/chromenetwork.png
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Dummy Title</title>
</head>
<body>
<form id="form1" method="post" action="Home/BookingConfirmation">
<div id="domWaitMessage">
<img src="Content/images/preloader.gif" alt="Please Wait...." />
</div>
</form>
</body>
</html>
UPDATE WORKING SCRIPT
代わりにgetAttribute("action")
を使用しての
<script type="text/javascript">
function changeHashOnLoad() {
window.location.href += "#";
setTimeout(changeHashAgain, 50);
}
function changeHashAgain() {
window.location.href += "1";
}
var storedHash = window.location.hash;
window.setInterval(function() {
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);
//do after all images have finished loading
$(window).load(function() {
changeHashOnLoad();
//show the wait message
$("#domWaitMessage").show();
//ORIGINAL REDIRECTION CODE
//window.location.href = document.forms[0].action;
//NEW WORKING REDIRECTION CODE
setTimeout(function() { window.location.href = document.forms[0].action; }, 100);
});
</script>
私はこれが*原因*であるとは思っていませんが、FYIでは、あなたのタイムアウト期間に文字列を使用しているという点であなたの 'setTimeout'は奇妙です。また、関数呼び出しのための文字列は必要ありません。その行を次のように置き換えることができます: 'setTimeout(changeHashAgain、50);' – Jacob
@Jacob、それを試みましたが、まだ動作しません。しかし、あなたの提案は、よりクリーンな、ありがとう! –