You can change this JS code to open the link in another tab when clicked

Asked

Viewed 122 times

0

I know no codes. If anyone can help me. This below is the JS code... it opens in the same tab the video... if you have how to change the code to open in a popup or in new tab, I would appreciate.

$(function() {

  var videohtml5 = $('.videoGallery .videohtml5');
  var liHeight = $('.videoGallery li').height();

  // BLOGGER
  videohtml5.click(function() {
    var videoID = $(this).attr('data-videoID');
    var videos = $('<div class="meuVideo"><center> <video width="100%" controls="controls" autoplay="true" poster="https://i.imgur.com/SoclbRY.png" src="https://www.blogger.com/video-play.mp4?contentId=' + videoID + '" type="video/mp4"></video></center> </div>');

    $('.meuVideo, .nowPlaying').remove();
    $(this).parents().eq(2).append(videos);

  });

  // Fechar Videos
  $('.close').click(function() {
    $('.meuVideo, .nowPlaying').remove();
  });

})
  • You can only do this if the user clicks on something (e.g., a "open video" button), otherwise the browser blocks the popup.

  • friend. this and test link look how it opens.. click on an episode to view http://programptostagem.blogspot.com.br/2017/10/strange-todos-episodios-formato.html

  • yes.. but you can change the code above. to open in another window or even in popup

  • This link explicitly asks you to turn off the ad block, and that’s why it works, otherwise it would certainly be blocked

  • friend vc be wrong... disabled the gadget. look there again and make the test it runs with ad block on

  • I tested it here and it runs with Adblock

  • I just tested it and saw the Adblock warning, but now I really don’t see it. It still won’t open in a new tab unless I explicitly turn off Adblock (as I did now to test)

  • friend. I think you’ve got it wrong.. when clicking on the episode it opens in the same tab... I wanted to know if there is a way to open it in another tab when clicked.. and kind when click it open on another..

  • and like this code ..

  • <div dir="Ltr" style="text-align: left;" trbidi="on"> <a href="https://www.blogger.com/video-play.mp4?contentId=%203906ae6d9485568c" target="_Blank">click here</a></div>

  • I just don’t know if it’s possible to do it in the js.. file I don’t know anything about html.. I don’t really know anything about programming

Show 6 more comments

1 answer

0


You can do it with the function window.open() and then insert the HTML with document.write. See that I changed the variable videos apart from the parentheses and the $:

$(function() {

  var videohtml5 = $('.videoGallery .videohtml5');
  var liHeight = $('.videoGallery li').height();

  // BLOGGER
  videohtml5.click(function() {
    var videoID = $(this).attr('data-videoID');
    var videos = '<div class="meuVideo"><center> <video width="100%" controls="controls" autoplay="true" poster="https://i.imgur.com/SoclbRY.png" src="https://www.blogger.com/video-play.mp4?contentId=' + videoID + '" type="video/mp4"></video></center> </div>';

    // Abro uma janela popup
    video_popup = window.open("pagina_da_popup.html","video_popup","width=400, height=200");

    $('.meuVideo, .nowPlaying').remove();

    // Insiro os dados na popup
    video_popup.document.write(videos);

  });

  // Fechar Videos
  $('.close').click(function() {
    $('.meuVideo, .nowPlaying').remove();
  });

})

Obs.: Where has pagina_da_popup.html, need not necessarily be an existing page on the server. Even if you do not put anything in the URL (thus: video_popup = window.open("","video_popup","width=400, height=200");) will work, because the popup is just a window from browser, and does not necessarily need to have a URL. It will only appear before the document.write take action, the message HTTP Error 404.0 - Not Found.

  • friend was just that.. but has only a small problem. the video opens but gets bigger than the screen. type has how to frame it on the screen after it expands. click and see in some episode the video opens in popup. but it gets bigger than the screen https://programrsostagem.blogspot.com.br/2017/10/strange-todos-episodios-formato.html

  • friend thanks for your help and time devoted to my problem.. I noticed here that the error is not in the code. and neither in the template of both sites.. pq changed the template of both and the error only continues on my original site.. must be some setup. on it... I’ll look here what’s wrong. thanks but once...

Browser other questions tagged

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