1

誰かが IE を使用して HTML ページを開いた場合に、HTML ページの値「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>

コードの変更のためにそこに何を入れなければならないか誰かが知っていますか?

4

2 に答える 2

0

JS を使用したくない場合は、条件付きコメントを使用できます。

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

これは、IEの条件付きコメント構文に関するフィドル別のリンクです。

于 2012-05-23T20:11:13.980 に答える
0

document.getElementById('troca').src=新しい値で再度呼び出すだけです。ブラウザは自分の appName について嘘をつくことができ、実際に嘘をつくことを知っておいてください。IE は Microsoft Internet Explorer である傾向がありますが、それ以外はほぼすべて Netscape として識別されます。

iframes には がなくhref、 のみがありsrcます。

于 2012-05-23T20:13:54.660 に答える