0

I have my 4 static HTML pages created as below.

  1. Home
  2. About
  3. Services
  4. Contact

On each page, there is a link, which opens up another static page called myVideo.html which plays video about me on a new tab.

I have kept that link on each page so that the user can open it up for anywhere.

The problem is, when it opens up from home page, it can again open from about page, so that makes the video autoplay two times which creates a bad impact.

What I want is, when the user has started the video from any page and when they again execute the same from another page, they should get an Alert mentioning that "The video is already being played on a new tab", so that my video plays only once. They can again play the video only on close of the tab which is playing that video.

My question is, is this possible ??

Nitesh
  • 15,425
  • 4
  • 48
  • 60
  • Is it an application in ASP.NET, PHP or is it pure HTML? – Nicolas Henrard Jun 24 '14 at 10:46
  • Pure HTML - @NicolasHenrard – Nitesh Jun 24 '14 at 10:48
  • You need a JS variable to set once the video is launched and check it if it is asked for again. You are also going to need to reset the variable when the user closes the video. – Dean.DePue Jun 24 '14 at 10:53
  • Could you provide me a very short example for what you mentioned above ? - @Dean.DePue – Nitesh Jun 24 '14 at 10:54
  • @Dean.DePue JavaScript can't do persistent things like this feature require... Ctrl+F5 and everything is done. – Nicolas Henrard Jun 24 '14 at 10:56
  • @NathanLee - I would do a search for passing values between pages with JS. But, you may have to resort to setting values in code behind like NicholasHenrard has indicated below. – Dean.DePue Jun 24 '14 at 10:58
  • So is this doable by PHP ?? I can integrate the PHP on my page, but will that store value like Nicholas mentioned JS cannot store on page refresh ?? - @Dean.DePue – Nitesh Jun 24 '14 at 11:01
  • @NicolasHenrard - I've passed values before between pages with JS and, yes, the user is able to reset everything by reloading the page. But, how accurate do you want to get? He's talking about showing a video about him, not very critical, I think. – Dean.DePue Jun 24 '14 at 11:01
  • @Dean.DePue - I like 100% reliable solutions... – Nicolas Henrard Jun 24 '14 at 11:03
  • But showing a video about me will come in the form of an .html page which will have that video embedded. Point is not of the video, but of the HTML page that will open as a new tab. - @Dean.DePue – Nitesh Jun 24 '14 at 11:03

3 Answers3

7

Use a target="" in the link. The target is meant for frames, but when you specify the same target name in every link the browser will open a new tab or window when no window with the name exists, and will reuse the existing window when it exists.

<a href="/link/to/video/" target="video">link</a>
Gerald Schneider
  • 17,416
  • 9
  • 60
  • 78
  • I haven't checked phones, but since this is common behaviour since the beginning of the web I'd expect them to do so. – Gerald Schneider Jun 24 '14 at 11:09
  • ok .. Let me do it practically on my pages and shall come back to you for any queries .. +1 for a very clean solution. – Nitesh Jun 24 '14 at 11:10
  • ok .. Here is what is happening .. when I play the video from home.html, it opens the video on a new tab via target="video". When I click on about.html, the tab, which is playing the video, reloads the video and starts to play from beginning and so on for the other pages. As mentioned in my question, the alert, what I mentioned, was to keep the player playing the video. Is this possible to keep the player playing the video instead of reloading it again ?? - @GeraldSchneider – Nitesh Jun 24 '14 at 11:22
  • No, this is not possible without extensive javascript that stores the current state in cookies or local storage or even on the server, which will not work on every client. The best you can do (and be sure that it's consistent for all visitors) is to make sure it's only played once and in the same tab/window. – Gerald Schneider Jun 24 '14 at 11:31
  • Thanks @GeraldSchneider for the reply. I shall stick to your original solution. As I need to play it for a different tab, so that the users dont get deviate from the main page. Just a last question. Is there a way to keep the users on the same tab and not redirect on myVid.html but myVid.html should open on a new tab ?? – Nitesh Jun 24 '14 at 11:56
0

Nearly everything is possible.

But this functionnality need some server-side script in my opinion.

The real problem is the impossibility of storing data in a file with JavaScript.

You can detect video events (exemple here: Detect when an HTML5 video finishes) but you're not able to make this information passing through pages.

A JavaScript-only solution will automatically fail when a user will refresh the page, eso...

Community
  • 1
  • 1
Nicolas Henrard
  • 843
  • 8
  • 19
  • So is this doable by PHP ?? I can integrate the PHP on my page, but will that store value like you mentioned JS cannot store on page refresh ?? – Nitesh Jun 24 '14 at 10:59
-1

You can handle this in jquery.

<a href="" title="" target="_blank" onclick="myFunction()" >content</a>

<script>
function myFunction() {
    window.open("http://stackoverflow.com","stackoverflow");
}
</script>
Aravind Sivam
  • 1,089
  • 8
  • 23