2012-05-23 34 views
1

如果有人使用IE打开它,我想在我的html页面中更改值“href”。 起初,我尝试了按钮,但最终的目标是没有它。在Internet Explorer上更改href

这是我有:

<script type="text/javascript"> 
function myFunction() 
{ 
var oldHTML = document.getElementById('troca').href="http://player.vimeo.com/video/39640718?title=0&amp;byline=0&amp;portrait=0" 
var newHTML = document.getElementById('troca').href="http://www.youtube.com/embed/VwjI7ICgcJ0?rel=0"; 
if (navigator.appName!='Microsoft Internet Explorer') 
    { 
    **//what action i have to put in here?** 
    } 
document.getElementById("troca").innerHTML=x; 
} 
</script> 

</head> 

<body> 
<p>clique, se for internet explorer nao vai trocar nada!</p> 

<button onclick="myFunction()">Troca</button> 

<br/><br/> 

<iframe id="troca" src="http://player.vimeo.com/video/39640718?title=0&amp;byline=0&amp;portrait=0" width="910" height="512" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> 

</body> 

是否有人知道我有什么就摆在那里我的代码修改?

回答

0

您可以使用conditional comments如果你不想使用JS:

<!--[if IE]> hello ie user! <![endif]--> 
<![if !IE]> 
hello non-ie user! 
<![endif]> 

这里有一个fiddleanother link关于IE条件注释语法。

+0

对不起,我更新了正确的语法 – Jason

+0

感谢兄弟!!!!! –

+0

没问题:)如果这个答案解决了你的问题,不要忘了点击答案旁边的复选标记! – Jason

0

只需使用新值再次调用document.getElementById('troca').src=即可。只要知道浏览器可以并且对他们的appName撒谎。 IE往往是Microsoft Internet Explorer,但几乎所有其他标识为Netscape。

iframe s没有href,只有src