Enable and disable window.location.href

Display name

Recently, YouTube introduced the new Autoplay feature and I got jealous.

enter image description here

I implemented it on my tube site. My site uses jwplayer as a video player, it has a very beautiful and easy API where a function there is called onComplete, where it will execute my javascript queries at the end of the video.

What I did is this:

onComplete:function() {
//Video has ended, now we redirect to the new video
window.location.href = "//www.mysite.com/video?id=33412";
}

So, using this, my site will successfully redirect to a new video, and so on. But, what if the user turns off the "Autoplay" feature as shown in the image. How can I disable the window.location.href?

Other stackoverflow answers said:

You can't change the window.location prototype, because this a "native property" of window and it is not configurable.

What would be the solution in my case? A solution using Jquery is okay for me too.

mohamedrias

For autoplay have a flag. Set/unset the flag.

In your onComplete, check the flag

onComplete:function() {
//Video has ended, now we redirect to the new video

// check the flag and execute
if(autoPlay) window.location.href = "//www.mysite.com/video?id=33412";

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

String is not a function on window location href

From Dev

window.location.href not working

From Dev

give info window if gps location not enable in browser

From Dev

onclick window.location.href with input value

From Dev

Javascript window.location.href onClick not working

From Dev

Passing parameter through "window.location.href"

From Dev

onchange event on window.location.href

From Dev

Window.location.href infinite loop

From Dev

Stubbing window.location.href with Sinon

From Dev

window.location.href not working in IE 11

From Dev

Using a variable for if window.location.href.indexOf()

From Dev

$window.location.href NOT WORKING in AngularJS

From Dev

window.location.href appending instead of replacing

From Dev

JavaScript window.location.href not working in localhost

From Dev

window.location.href is not redirecting html page

From Dev

window.location.href not working on IE

From Dev

How to Pass QueryString in window.location.href?

From Dev

onclick window.location.href with input value

From Dev

window.location.href - help redirecting

From Dev

Use of window.location.href in crosswalk

From Dev

window.location.href and hash are not working on chrome

From Dev

Window.location.href infinite loop

From Dev

Javascript window.location.href onClick not working

From Dev

find a tag that contains the window.location.href

From Dev

window.location.href not working as expected

From Dev

Passing parameters using Window.location.href

From Dev

`window.location.href` not working as intended

From Dev

window.location.href isn't working

From Dev

*ngIf window.location.href.indexOf is not working

Related Related

HotTag

Archive