1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jquery mobileにおける"Origin null is not allowed by Access-Control-Allow-Origin"の解決策

Posted at

*注:Webセキュリティに関して知識が乏しいため、解決策として間違っているかもしれません。造詣の深い方はご指摘ください。

jQueryMobileを用いると、ローカルで開発している場合(file:///...)においても、anchorタグのhref属性で別のファイルに遷移することができません。これは、jQueryMobileを加えると、anchorタグのリンク先にAjaxリクエスト(XMLHttpRequest)を送るようにするため、Same-Originポリシーに引っかかるからですが、解決策(?)はいくつかあるようです。

  1. jQueryMobile特有のdata-role="page"を用いて遷移(?)させる
  2. onclick='location.href="hoge.html"' で遷移させる(問題あり)
  3. rel="external"で外部リンクにしてしまう

2の方法は、StackOverFlowの質問で挙げられているように、javascriptで遷移するのはhtmlのつながりであるWebというシステム上、あまり良しとされていません。

3の方法もStackOverFlowの別の質問で挙げられているように、外部リンクにするとtransitionが失われてしまいます。

おそらくjQueryMobileが意図している正しい使い方は、1の方法で、これは1つのhtmlファイル内で遷移を行う際、data-role="page"属性のついているものを一つのページとして表示します。具体的には、

<div data-role="page" id="page1">
  <a href="#page2">to page2</a>
</div>
<div data-role="page" id="page2">
  page2
</div>

と設定することにより、見た目ではページが遷移したように見えます。htmlが長くなりがちですが、htmlではページという概念が定義されていないため、このようにせざるをえなかったのでしょうか。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?