Replace Iframes

Asked

Viewed 209 times

0

Hi, I wanted help to put together a script but I don’t know where to start.

I have a movie site, where I put video iframe. I wanted a script that identifies all these iframe and add an image about this iframe, that then when clicking on the image, will be redirected (in a new tab) to the url of this iframe.

  • If it is a list generated by PHP you don’t need a script to identify, just generate it in PHP itself. Very likely something very different from that will be a beautiful Ambi, if that is the scenario. And another, because are video iframes? could not just be a picture of some of the frames?

  • It is not generated by php... I take for example videos from Youtube and add to the site...

  • Manually add to HTML?

  • Yes. Ai type, the problem is all iframes already posted manually previously.... pq if I am redo will take a lot of work

1 answer

1

You can use the jQuery.each(): Example:

$(document).ready(function(){ 
  $("iframe").each(function() { 
  //src = source do iframe, no caso, o link para se redirecionar
  var src= $(this).attr('src');
  $(this).contents().html("<a href='" + src + "'><img src='link da imagem'></a>");
  });
});

It would look like the code above.

  • I tested this code there but it doesn’t work very well. It simply puts a gigantic image at the top of the site. I wanted him to cover only the iframe, you know? And it’s not opening the iframe link...it just captures the current url and adds some strange characters

  • The code isn’t complete, it could show how you interpreted it?

  • I don’t understand it very well, I’m very lay, but from what I understand, he checks if the page has iframe, and if there is, he displays this image. The problem is just the image, which type, is getting giant at the top of the screen, and not over the iframe, and the link that when you click on the image does not open in a new window the iframe link.

  • Friend, the code presented was just an example for you to try to do alone...

  • Ah, all right...

  • Can show how it was implemented?

  • I couldn’t really do it myself.... :(

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.