javascript - YouTube Iframe embedding causes redirect in IE7 -


this piece of code works every browser except ie7. in ie7, user redirected http://www.youtube.com. oh, , doesn't redirect frame, entire page redirected! thoughts? ideas? alternate patterns?

please me. ie killing live.

  $('.youtube .cue a').live('click', function(e) {     e.preventdefault();     var $this = $(this);     var $area = $this.parents('.youtube');     var $caption = $area.find('.videodescription');     var $li = $this.parents('li:first');     var vid = $.trim($(this).attr('href').replace('#', ''));     var title = $li.find('.title').text();     var time = $li.find('.time').text();     var description = $li.find('.description').text();      var $frame = $('<iframe></iframe>').attr({       width:595,       height:350,       frameborder: 0,       src: 'http://www.youtube.com/embed/' + vid     });      if (!hasflash) {       $area.find('.captioned').html('<a href="http://get.adobe.com/flashplayer/" class="no-flash">please install flash</a>.');     }     else {       $area.find('.captioned').html('').append($frame);     }      $caption.find('.title').html(title);     $caption.find('.time').html(time);     $caption.find('.description').html(description);   }); 

it looks me line:

var vid = $.trim($(this).attr('href').replace('#', '')); 

is problem. retrieving href <a> tag going return qualified url (including http:// , domain on front). then, in line, you're going add onto end of qualified url:

src: 'http://www.youtube.com/embed/' + vid 

that's going yield odd result this:

http://www.youtube.com/embed/http://www.domain.com/xxxxxx

for iframe src= attribute not want.

what may tripping retrieving href <a href="index.html"> tag retrieves qualified url, if page source has relative url. if want path or filename link href, have parse off.

i've verified reconstruction of your html , code if give sort of bad url iframe, redirect whole page (even in chrome). here's jsfiddle: http://jsfiddle.net/jfriend00/4p3dh/.

if hit run , click link says "click me", redirect whole page because of bad url on iframe.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -