change iframe source in ie using javascript

2019-01-23 05:01发布

I have used an iframe which looks like this:

<iframe style='width: 330px; height: 278px' scrolling='no' name="iframeId" class="advPlayer" id="iframeId" frameborder="0" src='../../player/iabpreview.php?adid=<?php echo $selectedAdIdx ?>&amp;autoPlay=true'></iframe>

Whenever I click on a <div>, I have to change the source of the iframe. I am using the following code:

if ($j.browser.msie) {            
  frames['iframeId'].window.location="../player/iabpreview.php?adid="+adId+"&autoPlay=true";
}else {
  $j(".advPlayer").eq(0).attr("src", "../player/iabpreview.php?adid="+adId+"&autoPlay=true");    
}

This works with Firefox, but not with Internet Explorer.

What code would work for Internet Explorer too?

标签: jquery iframe
13条回答
成全新的幸福
2楼-- · 2019-01-23 05:55

document.getElementById('MsgBoxWindow').getAttribute('src') works in Internet Explorer, Firefox, Safari, to get the source URL.

document.getElementById('MsgBoxWindow').setAttribute('src', urlwithinthedomain) works on the same browsers to set the source URL.

However, the iframe must be loaded before calling. Don't place it before the iframe while calling the JavaScript code. You can place both after the iframe, if you are calling it right after the page load, and it will work as expected.

查看更多
登录 后发表回答