5 Replies - 786 Views - Last Post: 15 August 2016 - 10:11 AM

#1 Desertt   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 182
  • Joined: 27-October 13

Change varibale status via js reload page

Posted 12 August 2016 - 06:27 AM

I have this code inlcude in all pages to resize window if width is changed
$(document).ready(function() {
	var playing = playing;
		if(playing === undefined || playing === null)
			playing = false;
                // Store the window width
		var windowWidth = $(window).width();
		// Resize Event
		$(window).resize(function(){
			alert(playing);
			if(!playing) {
			// Check window width has actually changed and it's not just iOS triggering a resize event on scroll
				if ($(window).width() != windowWidth) {
		
					// Update the window width for next time
					windowWidth = $(window).width();
					location.reload();
		
				}
		}
        // Otherwise do nothing

    	});

});


And i'm using this code in one page to check if you tube is clicked on full screen, if yes stop resizing else resize windows
function onYouTubeIframeAPIReady() {
		$('.MovieTrailer').each(function() {
			var frame = $(this);
			//create each instance using the individual iframe id
			var player = new YT.Player(frame.attr('id'), {
				events: {
				  'onStateChange': function(e) {
						playing  = true;
						if (e.data == YT.PlayerState.PLAYING) 
							playing = true;
						if (e.data == YT.PlayerState.PAUSED)
							playing = false;
						function reload_js(src) {
							$('script[src="' + src + '"]').remove();
							$('<script>').attr('src', src).appendTo('head');
						}
						reload_js('resize.js');	
				  }
				}
			  });
	
		});
	}



But the problem is the playing is always get back to false and if i remove
var playing = playing;
		if(playing === undefined || playing === null)
			playing = false;


From the first script file the page give error which is playing is not defined how can i define playing and changed it status

This post has been edited by Desertt: 12 August 2016 - 06:35 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Change varibale status via js reload page

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3134
  • View blog
  • Posts: 8,931
  • Joined: 15-January 14

Re: Change varibale status via js reload page

Posted 12 August 2016 - 11:09 AM

Quote

I have this code inlcude in all pages to [reload] window if width is changed

Why?

This is pointless:

var playing = playing;


You should add some console.log statements in to that event handler to make sure it's even being executed. Maybe that variable is never being set at all.
Was This Post Helpful? 0
  • +
  • -

#3 Nitewalkr   User is offline

  • D.I.C Lover

Reputation: 149
  • View blog
  • Posts: 1,045
  • Joined: 17-November 10

Re: Change varibale status via js reload page

Posted 13 August 2016 - 10:33 PM

You are missing a Boolean Parse, that should resolve the "playing is not defined" so var playing; playing = Boolean("true"); playing = Boolean("false"); in your conditions.

Also, ArtificialSoldier is right. var playing = playing is pointless.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Change varibale status via js reload page

Posted 14 August 2016 - 02:32 AM

Why would you write playing = Boolean("true"); rather than playing = true; ?

There are some odd cases where it might be argued that the construction new Boolean(/* expression */) is useful but not the explicit conversion of the literal values "true" or "false". There is nothing gained.
Was This Post Helpful? 1
  • +
  • -

#5 Desertt   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 182
  • Joined: 27-October 13

Re: Change varibale status via js reload page

Posted 14 August 2016 - 11:04 PM

ArtificialSoldier in the console log when i open youtube the code is executing and the player is changed between true and false on play and pause video.

Nitewalkr were should i initial the boolean in the resize script or in the script of youtube play and pause, i tried to put in the resize but it give me back that playing is not defined.
Was This Post Helpful? 0
  • +
  • -

#6 Nitewalkr   User is offline

  • D.I.C Lover

Reputation: 149
  • View blog
  • Posts: 1,045
  • Joined: 17-November 10

Re: Change varibale status via js reload page

Posted 15 August 2016 - 10:11 AM

You need to change the value of "var playing." You can make it = false or = Boolean("false"), but as Andrewsw pointed out that it shouldn't matter.

Also it is better if you post the code block that you have updated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1