Skip to content

Instantly share code, notes, and snippets.

@RyoSugimoto
RyoSugimoto / ajax_timeout.js
Created April 17, 2016 04:41
**Ajax通信にはタイムアウトを設定するべきである。**
// sample
$.ajax({
type: 'GET',
url: hogeURL,
cache: false,
timeout: 10000 // 10秒でタイムアウト
});
@RyoSugimoto
RyoSugimoto / supports.css
Created April 17, 2016 04:35
@supportsで、ブラウザのCSSプロパティサポート状況に応じて、ルールを切り替える。 # 参考 * http://www.webcreatorbox.com/tech/css-supports/
@supports (display: flex) {
.flexbox {
display: flex;
}
}
@RyoSugimoto
RyoSugimoto / send_referrer_on_redirect.js
Created February 5, 2016 09:34
JSによるリダイレクトを行なう際、リダイレクト元での参照元情報や検索パラメータを、リダイレクト先にも正しく引き渡すサンプル。 http://qiita.com/1987yama3/items/5ff58b6195fe6c3f268b
if ( isMobileDevice()) {
var redirect_url = "http://example.com/sp/index.html" + location.search;
if (document.referrer) {
var referrer = "referrer=" + encodeURIComponent(document.referrer);
redirect_url = redirect_url + (location.search ? '&' : '?') + referrer;
}
location.href = redirect_url;
}
@RyoSugimoto
RyoSugimoto / ga_redirect.js
Last active February 5, 2016 09:34
JSによるリダイレクトを行なう際に、リダイレクト先のHMTLに実装するスクリプト。GAのcreateと sendの間に記述することで、GAに正しい参照元情報を送ることができる。 http://qiita.com/1987yama3/items/5ff58b6195fe6c3f268b
ga('create', 'UA-0123456-1');
// ここから
if (location.search.indexOf('referrer=') >= 0) {
var params = location.search.replace('?', '').split('&');
for (var i = 0; i < params.length; i++) {
var kv = params[i].split('=');
if (kv.length == 2 && kv[0] == 'referrer') {
ga('set', 'referrer', decodeURIComponent(kv[1]));
break;
@RyoSugimoto
RyoSugimoto / reg_exp_char.md
Created November 2, 2015 08:29
正規表現一覧。
任意の1文字
記号 意味
.
@RyoSugimoto
RyoSugimoto / reg_exp_price.js
Last active November 2, 2015 08:20
カンマの入った価格のパターン。
/((|,)([0-9]{1,3})+)+円/
/*! normalize.css v1.1.3 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined in IE 6/7/8/9 and Firefox 3.
*/
@RyoSugimoto
RyoSugimoto / prevent_back.js
Last active August 29, 2015 14:25
HTML5のHistory APIを利用して、ブラウザの「戻る」を無効化する。
// このコードはjQueryを仕様しています。
if(window.history && window.history.pushState) {
var stateName = 'samePage';
history.pushState(stateName, null, null);
$(window).on('popstate', function (e) {
if (history.state === stateName) {
alert(history.state);
}
});
@RyoSugimoto
RyoSugimoto / readme.md
Last active August 29, 2015 14:22
ユーザーエージェントに応じてリダイレクトさせるJSライブラリ。

UARedirector.js

アクセスしてきた端末が指定したユーザーエージェントに当てはまるときに、指定したURLにリダイレクトさせるためのJavaScriptです。
jQueryなどのフレームワークに頼らずに、スタンドアローンで動作します。

基本的な使い方

まず、HTML文書内で「ua_redirector.js」を読み込ませます。

@RyoSugimoto
RyoSugimoto / ios_version.js
Created May 26, 2015 05:49
iOSのバージョンを調べる。
var iOSversion = function () {
if (/iP(hone|od|ad)/.test(navigator.platform)) {
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
return [parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)];
}
};