How to leave an entire page clickable linked to a button?

Asked

Viewed 148 times

0

how can I leave an entire page clickable linked to a button? Example: http://jsfiddle.net/u06oowLn/ when the person clicks on any area of the site click on the play button or on the youtube video that will ta on the page, as if it were an ad invisible throughout the page, leaving clickable

  • Change "#btnPlay" for document in jquery

  • Question: What is the purpose of this code?

2 answers

1

sfiddle

Just associate the click event to document instead of the id of the button #btnPlay

Library

<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.js"></script>

<script type="text/javascript" src="https://www.youtube.com/iframe_api"></script>

Script: you must set the video in videoId: 'YeiYa70RxRc'

$(window).load(function(){
var player = new YT.Player('player', {
    width: 540,
    height: 320,
    videoId: 'YeiYa70RxRc'
});

$(document).on("click", function() {
    player.playVideo();
});
});

Html

<div id="player"></div>
  • I edited the answer and put jsfidle. Show what you tried to do

  • The library is missing, open http://jsfiddle.net/u06oowLn/ replace the code with your own and then click Fork to give you a new url with your example. But if you do as is in the reply and publish on your server, it will work. I also don’t know how to put the library in this jsfidle.

  • @Thiagosc posted his video in the jsfidle of the answer http://jsfiddle.net/ugbg5bwt/

  • I’m not a salesman. Just wanting to learn by teaching. Feel free, if I can help you I will help you.

  • Did not understand well, the video inside an iframe? and the invisible video or invisible iframe? Clicking on the page area the video would become visible? or the iframe would become visible?

0

You can link a click event to the window or Document, with javascript, so when anywhere on the screen or document is clicked this event will be executed

$(window).click(function() {
    console.log("Botão clicado")
});

or

$(document).click(function() {
console.log("Botão clicado")
});

Browser other questions tagged

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