忍者ブログ

★黒猫宅急便★ver.2

( *´艸`) いらっしゃいまし。



[1433]  [1432]  [1425]  [1430]  [1426]  [1428]  [1427]  [1431]  [1429]  [1424]  [1422

entry_top_w.png
先日やった、JavaScriptによるブラウザ判別を利用して、Flashでブラウザによって処理を変えることをやってみた。
 

お気に入りに登録っていう処理
window.external.AddFavorite(location.href, document.title);

コレ実は、Windows IE 4.0以降でしか機能しないんだよね。
知ってた?オレは、知らなかった。

FIreFoxお気に入りに登録させるスクリプトは、、、
window.sidebar.addPanel(location.href, document.title);

んで、Safariについては非対応?らしい。
さらにMacのブラウザについては、IEであっても非対応。

なので、非対応ブラウザについては、その旨についてのアラートを表示するという処理をやってみた。


Flashのアクションスクリプトから、html側に記述したjavascript関数を呼び出しブラウザ判別の処理をさせる。今回は、この処理にExternalInterface使用した。
ただし、ブラウザ(特にIE)によって、flashとjavascriptでの処理速度の違いにより値の受取がうまく機能しないため、Flashの貼り付けタグに id="externalkuro" を追加し、対応。
※ id="" の記載文字は、"~external" or "external~" のどちらでも可ってことらしい。


今回のソースコード
<html側>
-----------ここから-----------
<script type="text/javascript">
<!--
function javaagent(){
var ua = "";
var useagent = "";
 ua = window.navigator.userAgent.toLowerCase();
 if(ua.indexOf("msie") > -1){
  useagent = "msie";
 }
 else if(ua.indexOf("firefox") > -1){
  useagent = "firefox";
 }
 else{
  useagent = "etc";
 }
 return useagent;
}
// -->
</script>
<br />
<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="150" height="50" id="externalkuro">
<param name="allowScriptAccess" value="always">
<param name="movie" value="xxx.swf">
</param>
<embed src="xxx.swf" type="application/x-shockwave-flash" allowscriptaccess="always" width="150" height="50">
</embed>
</object>
-----------ここまで-----------


<Flash側>
-----------ここから-----------
on(press){
 //ExternalInterfaceの使用
 import flash.external.ExternalInterface;
 //userAgentの取得 
 _global.agent =
ExternalInterface.call("javaagent");
 

 //取得したブラウザ情報で、処理分け
 if(_global.agent == "msie"){
  getURL("JavaScript:window.external.AddFavorite(location.href,document.title);");
 }
 else if(_global.agent == "firefox"){
  getURL("JavaScript:sidebar.addPanel(location.href,document.title);");
 }
 else if(_global.agent == "etc"){
  getURL("javascript:alert('Windows Internet Explorer4.0以降でのみ実行可能');");
 }
 else{
  getURL("javascript:alert('Windows Internet Explorer4.0以降でのみ実行可能');");
 }
}
-----------ここまで-----------


ランキング参加中!
ブログランキング・にほんブログ村へ
entry_bottom_w.png

この記事にコメントする

お名前
コメントタイトル
色変更
URL
コメント本文
パスワード Vodafone絵文字 i-mode絵文字 Ezweb絵文字



この記事へのトラックバック

この記事にトラックバックする:
plugin_top_w.png
かうんたー


現在の閲覧者数:
plugin_bottom_w.png
plugin_top_w.png
きじ検索
plugin_bottom_w.png
plugin_top_w.png
記事らんきんぐ

plugin_bottom_w.png
plugin_top_w.png
広告


plugin_bottom_w.png
plugin_top_w.png
その他


参加中
ブログランキング・にほんブログ村へ
plugin_bottom_w.png
plugin_top_w.png
あくせすらんきんぐ
plugin_bottom_w.png
plugin_top_w.png
ぷろふぃーる
HN:黒猫★
年齢:2さい
性別:♂オス
生誕:5月25日(日)
職業:魔女の子分
趣味:倶楽部活動

plugin_bottom_w.png
plugin_top_w.png
最新こめんと
[10/03 30bB]
[02/13 ★黒猫★]
[01/29 のら猫]
[11/04 ★黒猫★]
[11/03 ゆーき]
plugin_bottom_w.png
plugin_top_w.png
広告3
plugin_bottom_w.png
plugin_top_w.png
ブログ ver.4
plugin_bottom_w.png

PR


Copyright ★黒猫宅急便★ver.2 by ★黒猫★ All Rights Reserved.
忍者ブログ [PR]