I have this simple iframe:
我有这个简单的iframe:
<iframe src='http://edition.cnn.com/2014/05/23/world/asia/thai-coup-color-day-2/index.html?hpt=hp_c1#cnnContentContainer' class='ExFrame' id='ifr' style='width:100%;height:500px;' scrolling='yes'>
But when I load the page, the iframe gets the focus. Is it possible to prevent this? I tried this:
但是当我加载页面时,iframe获得了焦点。有可能阻止这种情况吗?我试过这个:
$("#ifr").blur();
With no luck...
没有运气......
http://jsfiddle.net/ELRxm/
EDIT: I want to use the #ID in the iframe's url
编辑:我想在iframe的网址中使用#ID
3 个解决方案
#1
0
Just remove #cnnContentContainer
at the end of the url:
只需删除网址末尾的#cnnContentContainer:
<iframe src='http://edition.cnn.com/2014/05/23/world/asia/thai-coup-color-day-2/index.html?hpt=hp_c1' class='ExFrame' id='ifr' style='width:100%;height:500px;' scrolling='yes'></iframe>
http://jsfiddle.net/ELRxm/1/
#2
0
You will want to check the Javascript to see what is going on with the frame; it may be setting the focus.
您将需要检查Javascript以查看框架的运行情况;它可能正在设定焦点。
By eliminating the javascript in your code:
通过消除代码中的javascript:
$("#ifr").blur();
, and changing the src
I found the focus just remains okay in this fiddle: http://jsfiddle.net/sablefoste/8gtLW/1/
,并改变srcI发现焦点在这个小提琴中仍然没问题:http://jsfiddle.net/sablefoste/8gtLW/1/
* EDIT *
*编辑*
Per @A. Wolff's comment, the #
tells the browser to focus on the specific content. But you should watch for both this and Javascript in website's you don't own, they can both make a difference.
Per @A。沃尔夫的评论,#告诉浏览器专注于具体内容。但你应该注意这个和你不拥有的网站上的Javascript,它们都可以有所作为。
#1
0
Just remove #cnnContentContainer
at the end of the url:
只需删除网址末尾的#cnnContentContainer:
<iframe src='http://edition.cnn.com/2014/05/23/world/asia/thai-coup-color-day-2/index.html?hpt=hp_c1' class='ExFrame' id='ifr' style='width:100%;height:500px;' scrolling='yes'></iframe>
http://jsfiddle.net/ELRxm/1/
#2
0
You will want to check the Javascript to see what is going on with the frame; it may be setting the focus.
您将需要检查Javascript以查看框架的运行情况;它可能正在设定焦点。
By eliminating the javascript in your code:
通过消除代码中的javascript:
$("#ifr").blur();
, and changing the src
I found the focus just remains okay in this fiddle: http://jsfiddle.net/sablefoste/8gtLW/1/
,并改变srcI发现焦点在这个小提琴中仍然没问题:http://jsfiddle.net/sablefoste/8gtLW/1/
* EDIT *
*编辑*
Per @A. Wolff's comment, the #
tells the browser to focus on the specific content. But you should watch for both this and Javascript in website's you don't own, they can both make a difference.
Per @A。沃尔夫的评论,#告诉浏览器专注于具体内容。但你应该注意这个和你不拥有的网站上的Javascript,它们都可以有所作为。