2014年9月8日月曜日

ダブルクリック防止

ボタンを押してもなかなかページ遷移してくれない、なんて場合、ユーザはポチポチポチボタンを押してしまうことはよくあること。

そこで二重クリック防止のjavascriptをメモ

html
<button type="button" id="b" onclick = "noclick();">
<font size="1">ダブクリすんな</font>
</button>

javascript
function noclick(){
document.getElementById("b").disabled = true;
setTimeout('ダブクリさせない!', 0);
}

IE7以下では動かんのであしからず


あと、メモ
http://knt45.hatenablog.com/entry/20120821/1345512989

2014年8月25日月曜日

子フレームにダイレクトアクセスされた場合の対処法

子フレームにダイレクトアクセスされた場合の対処法

index.htmlにてiframeで読み込んでいるchild.htmlが、ユーザにダイレクトアクセスされた時に別ページに飛ばす方法をメモ。
他にいい方法あるかな…


child.htmlに下記のjavascriptを埋め込みロード時に実行する。
window.onload = function(){
var url = window.top.location.href.toLowerCase();
var index = "http://hogehoge/index.html"
url=url.substring(0,url.indexOf("?"));

  if(url  != index){
  location.href = "http://hogehoge/error.html";
  }
}

url比較時は、大文字小文字の区別が生じない、パラメータを無視するといったところに配慮。
javascriptが使えないブラウザではどういう対処をしているのか、ようわからない…

2014年8月6日水曜日

子フレームから親フレームを呼び出す

親フレームで読み込んでいるiframeから、親フレームの関数を呼び出します。

親フレーム========================
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>親フレーム</title>

<script language="JavaScript">
function testalert(){
alert('お父さんだよ');
}
</script>

</head>
<body>

<iframe src="./iframe.html" height=300 width=300 name="hey">
</iframe>

<iframe src="./iframe2.html" height=300 width=300 name="heyhey">
</iframe>

</body>
</html>


子フレーム1====================
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>子供1</title>
<script language="JavaScript">
function call(){
alert("兄弟だよ");
window.parent.testalert();
}
</script>
</head>
<body>
<input type="button" value="親を呼びます" onclick = "call()">
</body>
</html>

子フレーム2====================
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>子供2</title>
<script language="JavaScript">
function call(){
  alert("iframe2");
  window.parent.frames['hey'].call();
}
</script>
</head>
<body>
<input type="button" value="兄弟と親を呼びます" onclick = "call()">
</body>
</html>


子フレーム1
window.parent.testalert();

子フレーム2
window.parent.frames['hey'].call();

が重要。


デバッグ時の注意:Chromeはローカル実行するとエラー出ます。
サーバに置けば問題無いのではっていう 多分

2013年6月25日火曜日

R2D

GUIをやるべくruby2.0から使えるR2Dというのを導入することに

https://github.com/takaokouji/r2d


$git clone https://github.com/takaokouji/r2d.git
まずgitで落としてきましょう。

$gem install r2d
これをやるとそれらしい返答がきますが、嘘らしいです。

gitで落としてきたら、そのフォルダに入ります。
$ cd r2d
Version '2.0.0' is to confusing to select ruby interpreter.
なんか怒られますが、そのまま無視で問題なかったです(私は)

$gem build r2d.gemspec
これを打ってbuildします。

  Successfully built RubyGem
  Name: r2d
  Version: 0.0.0
  File: r2d-0.0.0.gem

こんな返答だったら大丈夫のはず。

これでインストール開始!

$ gem install --local r2d-0.0.0.gem
ERROR:  While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: r2d requires gosu (~> 0.7.47.1)
UserName-no-MacBook-Air:r2d UserName$ port install gosu
Warning: port definitions are more than two weeks old, consider using selfupdate
Error: Insufficient privileges to write to MacPorts install prefix.

gosuがないと怒られているので、gemで入れます。

$ gem install gosuFetching: gosu-0.7.47.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed gosu-0.7.47.1
1 gem installed
Installing ri documentation for gosu-0.7.47.1...
unable to convert "\xCF" from ASCII-8BIT to UTF-8 for lib/gosu.bundle, skipping
Installing RDoc documentation for gosu-0.7.47.1...
unable to convert "\xCF" from ASCII-8BIT to UTF-8 for lib/gosu.bundle, skipping

gosuが入ったらgemでインストール

$ gem install --local r2d-0.0.0.gem
Successfully installed r2d-0.0.0
1 gem installed
Installing ri documentation for r2d-0.0.0...
Installing RDoc documentation for r2d-0.0.0...

これで導入おしまい!!!
exampleの中にサンプルがあるので、動かしてみましょう。





Ruby2.0.0を導入するまでのあれこれ2

前回はrvmにRuby2.0.0-p195を入れることまではできたが、
肝心なuseができなかった。そこのところを調べて修正
まあ、結局友達に聞いたわけですがorz

$ rvm use ruby-2.0.0-p195

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

前回のエラーです。どうやらターミナルが最初に読み込むbashに問題あったようです

通常Macのターミナルではbashを最初に読み込み、そのタイミングでbashrcを読み込みます。
bashrcには
source "$HOME/.rvm/scripts/rvm"
というのを書く必要があったのですが、まずここでスペルミスをしていたという痛い事故が発生していました。これも大問題の一つだったわけですが、それ以上に問題がありました。bashがbashrcを読み込んでいなかったんです。なんでなのかようわからん。しらん。

そこでbashが読み込むbash_profileに以下の設定を追加しました。

# set rvm PATH
export PATH=$PATH:/Users/UserName/.rvm/bin/  #もともと書かなきゃいけない
source $HOME/.bashrc  #ここが重要

これでbash_profileが読み込まれるついでにbashrcがよみ込まれ、めでたくrvmが動くわけです。長かった・・・・

なんでbashがbashrcを読まなかったのかは、また今度暇な時に調べます。
いろいろ間違ってたら、ごめんなさい。

2013年6月22日土曜日

Ruby2.0.0を導入するまでのあれこれ

Ruby2.0を利用しなければならないけど
rvmの不具合を放置していたため詰んでる途中です
メモメモ

$ rvm install ruby-2.0.0-p195  →→エラー
$ less /Users/arakawahikari/.rvm/log/ruby-2.0.0/fetch.log を確認
$ rvm install ruby-2.0.0-p195 --verify-downloads 1 でうまくいくようだ

$ rvm use ruby-2.0.0-p195

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.

$ /bin/bash --login

$ rvm use ruby-2.0.0-p195

RVM is not a function, selecting rubies with 'rvm use ...' will not work.

You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.


とりあえず https://rvm.io/integration/gnome-terminal/ を確認する

 

2013年6月7日金曜日

CSVをMySQLに読み込ませる

できると便利だね、ということでやってみることに。
だが、カラムが多すぎていろいろとうまくいきませんでした。
インポート自体はできるので、あとは何かな、注意力のなさですかね^0^
mysql5です

> mysql5 --local-infile=1 -uUSERNAME -pPASSWORD TOURISM
まずはこれでログインします。
--local-infile=1 をつけておかないと、幸せになれません。

mysql>create database HOGE;
mysql>use HOGE;
mysql>create table HOGEHOGE(
           ・・・・・
           );
mysql> desc HOGEHOGE;  ちゃんとできてるか確認

データベースと、CSVのデータにあわせたテーブルを作ってやります。
お金を取り扱う場合、intではなくDECIMALがいいそうな。
型についてはあんま調べてません。昔の記憶を頼りに。

CSVをインポート
mysql> LOAD DATA LOCAL INFILE "CSVデータがある絶対パス"  INTO TABLE テーブル名 FIELDS TERMINATED BY ',';

これで挿入完了でございます。
なんか失敗したなって時は、テーブルを空にしましょう
mysql> truncate table 2008basic_ans;

--local-infile=1をつけてログインした理由は、LOAD DATA LOCAL INFILEを使うためです。

おしまい。