Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp sometimes and works and sometimes not

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
GB
Works in FireFox. Doesn't work in MSIE. In MSIE, the src="something" remains unchanged. Can someone please suggest the cause?

Many thanks,

Code:
<script>
function ViewAsx(videoCode) {
  videoCode = 'AsxGenerator.aspx?fn=' + videoCode;
  var v = document.getElementById('video');
  v.innerHTML = v.innerHTML.replace(/src="(.+?)"/, 'src="' + videoCode + '"');
  alert(v.innerHTML);
}
</script>

<a href="javascript:ViewAsx('somewhere')">link</a>

<div id="video">
<embed src="something"></embed>
</div>

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Well, because I think that using DOM is very gentle to the browsers and does not encourage them to automatically play the injected videos.

Thank you for spotting Microsoft's missing quotes. Maybe this isn't the best fix but it will do :)

Code:
if (document.all) v.innerHTML = v.innerHTML.replace(/src=(.*?) /, 'src=' + videoCode + ' ');
else v.innerHTML = v.innerHTML.replace(/src="(.+?)"/, 'src="' + videoCode + '"');

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top