flash javascript 設為首頁語法 安全性限制

心得筆記 2009/02/09 05:00

今天早上遇到一個AS無法成功執行JS的問題,
我想做的功能是,使用者瀏覽SWF然後點擊SWF裡的BTN之後,跳出詢問是否將某個網址設為該瀏覽器的首頁的對話框,實做的流程就是由AS的GETURL或EXTERNALINTERFACE去呼叫頁面上的JS,該JS在去實作將某個網址設為該瀏覽器的首頁的功能

再AS的語法如下

import flash.external.*;

yahoo.onRelease = function() {
 ExternalInterface.call("hi","me");
 //getURL("javascript:hi('hi')", "me");
 //getURL("javascript:var newdiv=document.createElement('div');newdiv.id='divblock';document.body.appendChild(newdiv);newdiv.style.behavior='url(#default#homepage)';newdiv.setHomePage('twimtv.im.tv');");
};


在嵌入該SWF的HTML(main.html)語法如下

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>test</title>
<script language="javascript">
function hi(srt){
alert(srt);
var newdiv=document.createElement('div');
newdiv.id='divblock';
document.body.appendChild(newdiv);
newdiv.style.behavior='url(#default#homepage)';
newdiv.setHomePage('http://twimtv.im.tv');
}
</script>
</head>
<body>
<a href="javascript:"></a>
<input type="button" name="dd" onClick="javascript:hi('55')" value="bbfff"/>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="IFCall" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="IFCall.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="IFCall.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="IFCall" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>

用IE瀏覽main.html發現

點擊頁面上的bbfff這個按鈕(非SWF上的按鈕)是可成功執行的(代表這段JS在IE上是正確的)

點擊SWF上的YAHOO這個按鈕,ALERT有成功跳出(代表AS呼叫JS成功),可是卻沒有跑將某個網址設為該瀏覽器的首頁的功能...

上網GOOGLE了一下,看起來像是安全性的限制,看來非要使用者點擊了IE上的按鈕才會觸發這個功能,於是我將這個問題貼上AUG(前MMUG)的M群,經TICORE大的建議將 wmode 設為 opaque~~
對話內容如下:
{id: "Ticore"}; // 說:
 或許可以試試看,將 wmode 設為 opaque~~

x:Allenliao...3.0...想學FMS的人密我~噹噹人 說:
 我試試~^^

{id: "Ticore"}; // 說:
 因為 wmode=window 模式, plugin 上的滑鼠事件與瀏覽器分開的
 將 wmode 設為 opaque~
可能可以讓瀏覽器能抓到使用者點擊的事件

x:Allenliao...3.0...想學FMS的人密我~噹噹人 說:
 成功了
 將 wmode 設為 opaque~~

{id: "Ticore"}; // 說:
:D

於是乎~HTML改成:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>test</title>
<script language="javascript">
function hi(srt){
alert(srt);
var newdiv=document.createElement('div');
newdiv.id='divblock';
document.body.appendChild(newdiv);
newdiv.style.behavior='url(#default#homepage)';
newdiv.setHomePage('http://twimtv.im.tv');
}
</script>
</head>
<body>
<a href="javascript:"></a>
<input type="button" name="dd" onClick="javascript:hi('55')" value="bbfff"/>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="IFCall" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="wmode" value="opaque" />
<param name="movie" value="IFCall.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="IFCall.swf" quality="high" wmode="opaque" bgcolor="#ffffff" width="550" height="400" name="IFCall" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>

就成功了!
讓我們來測看看FF
...幹...失敗了
(待續)

實測發現,FF擋更兇,他管你是不是從頁面上點擊觸發的,一率都擋,所以已經和FLASH沒關係了
GOOGLE找到範例
HTML改成:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script language="javascript">
function hi(srt){
alert(srt);
setHomepage('http://www.im.tv')
}


function setHomepage(pageURL)  
{  
 if (document.all)  
    {  
        document.body.style.behavior='url(#default#homepage)';  
  document.body.setHomePage(pageURL);  
   
    }  
    else if (window.sidebar)  
    {  
    if(window.netscape)  
    {  
         try 
   {    
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");    
         }    
         catch (e)    
         {    
    alert( "瀏覽器拒絕此操作,請在地址欄內輸入 about:config 然後將 signed.applets.codebase_principal_support 設為true" );    
         }  
    }   
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);  
    prefs.setCharPref('browser.startup.homepage',pageURL);  
 }  


</script>
</head>
<body>
<a href="javascript:"></a>
<input type="button" name="dd" onClick="javascript:hi('55')" value="bbfff"/>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550"

height="400" id="IFCall" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="wmode" value="opaque" />
<param name="movie" value="IFCall.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="IFCall.swf" quality="high" wmode="opaque" bgcolor="#ffffff" width="550" height="400" name="IFCall" align="middle" allowScriptAccess="always" type="application/x-

shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>


若偵測出被瀏覽器擋住這項操作,會ALERT出一個訊息教你調整FF


top
TAG

Trackback Address :: http://diary.tw/allenliao/trackback/706

  1. Tracked from &#35821;&#27861; 2010/08/19 10:21 DELETE

    Subject: &#35821;&#27861;

    &#35821;&#27861;
  2. Tracked from &#28120;&#23453; 2010/10/14 14:00 DELETE

    Subject: &#28120;&#23453;

    &#26080;&#24551;&#36141;&#29289;
  1. north face denali jacket 2012/03/31 07:49 MODIFY/DELETE REPLY

    <a href="http://www.northface-jacketoutlet.com/">North Face Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Denali Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Jacket Outlet </a> <a href="http://www.northface-jacketoutlet.com/">NorthFace Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">North Face Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">The North Face Denali Jacket</a> <a href="http://www.northface-jacketoutlet.com/">NorthFace Jackets Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">North Face Denali Jacket</a> <a href="http://www.northface-jacketoutlet.com/">North Face Denali Fleece Jacket</a> <a href="http://www.northface-jacketoutlet.com/">North Face Denali Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">North Face Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Denali Jackets</a> <a href="http://www.northface-jacketoutlet.com/">North Face Denali Fleece Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">NorthFace Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Outlet North Face Jacket</a> <a href="http://www.northface-jacketoutlet.com/">Outlet North Face</a> <a href="http://www.northface-jacketoutlet.com/">Outlet NorthFace</a> <a href="http://www.northface-jacketoutlet.com/">North Face Denali Fleece Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Denali Fleece Jacket Outlet</a> <a href="http://www.northface-jacketoutlet.com/">Wholesale North Face</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Denali Jacket</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Jacket</a> <a href="http://www.northface-jacketoutlet.com/">Cheap North Face Denali Jackets</a> <a href="http://www.northface-jacketoutlet.com/"> North Face pink ribbon Denali Fleece Jacket </a> <a href="http://www.thenorthfacedenalijackets.com/">Cheap NorthFace Denali Jackets</a> <a href="http://www.thenorthfacedenalijackets.com/">Cheap North Face Denali Jackets </a> <a href="http://www.thenorthfacedenalijackets.com/">North Face Denali Fleece Jacket</a> <a href="http://www.thenorthfacedenalijackets.com/">Cheap The North Face Denali Jackets</a> <a href="http://www.thenorthfacedenalijackets.com//">The North Face Denali Jacket</a> <a href="http://www.thenorthfacedenalijackets.com/">NorthFace Denali Jackets</a> <a href="http://www.thenorthfacedenalijackets.com/">Cheap North Face Denali Fleece Jacket</a> <a href="http://www.thenorthfacedenalijackets.com/">North Face Denali Jackets</a> <a href="http://www.thenorthfacedenalijackets.com/">North Face Denali Fleece Jackets</a> <a href="http://www.thenorthfacedenalijackets.com/">North Face Denali Jacket</a> <a href="http://www.thenorthfacedenalijackets.com/">North Face Denali Fleece Jackets Outlets</a> <a href="http://www.thenorthfacedenalijackets.com/">Cheap North Face Denali Jackets</a> <a href="http://www.thenorthfacedenalijackets.com/">NorthFace Denali Fleece Jackets</a><a href="http://www.northfacejacketwholesale.com/">NorthFace Wholesale</a> <a href="http://www.northfacejacketwholesale.com/"> North Face pink ribbon Denali Fleece Jacket </a> <a href="http://www.northfacejacketwholesale.com/">Wholesale NorthFace </a> <a href="http://www.northfacejacketwholesale.com/">North Face Jacket Wholesale</a> <a href="http://www.northfacejacketwholesale.com/">NorthFace Jacket Wholesale</a> <a href="http://www.northfacejacketwholesale.com/">Wholesale North Face Jacket</a> <a href="http://www.northfacejacketwholesale.com/">Wholesale NorthFace Jacket</a> <a href="http://www.northfacejacketwholesale.com/">Wholesale North Face Denali Jacket</a> <a href="http://www.northfacejacketwholesale.com/">Cheap North Face Wholesale</a> <a href="http://www.northfacejacketwholesale.com/">Cheap North Face pink ribbon Denali Fleece Jacket </a> <a href="http://www.northfacejacketwholesale.com/">Cheap NorthFace Jacket Wholesale</a> <a href="http://www.northfacejacketwholesale.com/">Cheap North Face Jackets Outlet/a>

Write a comment


PREV : [1] : ... [12] : [13] : [14] : [15] : [16] : [17] : [18] : [19] : [20] : ... [80] : NEXT