您的位置:首页 > Web前端 > HTML

Silverlight嵌入到HTML之windowless属性及运用AjaxControlToolKit时出现虚线边框的问题

2015-09-17 10:49 661 查看
Silverlight程序最终是要以<object />的形式嵌入到HTML里的,这就涉及怎么和HTML元素进行布局的问题。silverlight-plugin有个windowless属性,当windowsless属性值设置为false时,silverlight在HTML里就以子窗口的形式出现,即silverlight程序的展现由单独的窗口来处理,与其他html元素的展现是相互独立的。例如代码:

<div id="silverlightControlHost" style="height:160px;width:300px;">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2">
<param name="source" value="ClientBin/TestWindowlessProperty.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="transparent" />
<param name="windowless" value="false" />
<param name="minRuntimeVersion" value="2.0.31005.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>

<div style="width:250px;height:160px;background:gray;">
This is HTML DIV Element<br />
This is HTML DIV Element<br />
This is HTML DIV Element<br />
This is HTML DIV Element<br />
This is HTML DIV Element<br />
</div>


在浏览器中显示的如下:

<Script>
document.getElementById("silverlightObjectElementId").tabIndex = 0;
</Script>


Code
这时,当鼠标点击Silverlight程序时,周围就会浮现虚线边框,如图:



为解决这个问题,我尝试了几种方法:

1、在IE下:

1)可以在<object />元素的onfocus事件进行处理,让它不要得到焦点:

<script language=javascript>
document.getElementById("silverlightObjectElementId").onfocus = function() {
if (this.tabIndex != -1) {
      this.blur();
this.tabIndex = -1;
}
}
</script>


2) 可以在引用silverlight的<object>元素中直接将tabindex设置为-1,这样在AjaxControlToolkit的js中运行restoreTab()函数后silverlight的tabindex仍旧是-1而不是0,避开了由此导致的虚线边框问题。 <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="width:200px;height:200px;" tabIndex=-1 >

3) 在<object>标签中直接加上hidefocus属性,即: <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="width:200px;height:200px;" HideFocus=true>

4) 可以在onpropertychange事件里做一些处理。

2、在FireFox下:

1) 添加样式outling:none,即: <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" style="width:200px;height:200px;outline:none;" >

2) 在事件oninput里做一些处理(未尝试)。

原文链接:http://www.cnblogs.com/qguohog/archive/2009/04/11/1433676.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: