モバイルデバイスで正しく表示する必要があるWebページがあります。そのために、ページのヘッドにJQueryMobileスクリプトをロードしました。ヘッドタグは次のようになります。
<head>
<title>Page Title</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
</head>
また、ページの本文要素で使用され、データロール属性を使用して表示します。ページはモバイルデバイスでは非常に見栄えがしますが、リクエストがモバイル以外のブラウザから送信された場合でも同様に見えます。
リクエストがモバイルデバイスからのものである場合にのみ、JQueryMobileスクリプトをロードする方法を誰かが知っているかどうかを知りたいです。
私がこれまでに試したことは、ユーザーエージェントを検出し、モバイルデバイスの場合はスクリプトをロードする関数を使用することです。
function init() {
if(isMobile()) {
document.write('<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />');
document.write('<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>');
dcument.write('<script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>');
}
}
function isMobile() {
if(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/iPhone|iPad|iPod/i) || navigator.userAgent.match(/IEMobile/i))
return true;
return false;
}