Need help with some custom javascript code

jquery

#1

Hi

I have a javascript code on some friends website that i want to make work but i don't know javascript very good.

I need to code accept only few values from <title> tag from header in html, like Home, About, Contact

Here is a code

    var title = event.match(/<title[^>]*>([^<]+)<\/title>/)[1];
    $('head title').html( title );

    console.log("TITLE = " + title);

#2

You should be able to access the title with just document.title


#3

Can you give me some example because me and javascript are not very good :smiley:

Error i have all the time is "Uncaught TypeError: Cannot read property 'match' of undefined" and all titles in my head tag are same


#4

How many titles have you got? Hopefully you mean one title per page.


#5

Yes only title per page normally.

But as i see when i try to remove that ga function throws me error ga is not defined

   FullPageDestroy();		
   $('main').html(section);
				
   var title = event.match(/<title[^>]*>([^<]+)<\/title>/)[1];
   $('head title').html( title ); // this setup title
				
   //if browser doesn't support CSS transitions - dont wait for the end of transitions
  var delay = ( transitionsSupported() ) ? 30 : 0;
  setTimeout(function(){
	$('body').removeClass('page-is-changing');
	$('.cd-cover-layer').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
	isAnimating = false;
        $('.cd-cover-layer').off('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend');
});				
				
ga('set', 'page', '/' + url); // here i get error if i remove title
ga('send', 'pageview');

Here is full function

          function loadNewContent(url, bool) {
				url = ('' == url) ? 'index.html' : url;
			
			var section = $('<div class="cd-main-content "></div>');			
				
				
			section.load(url+' .cd-main-content > *', function(event){
				
				// load new content and replace <main> content with the new one
				FullPageDestroy();		
			    $('main').html(section);
				
				//var title = event.match(/<title[^>]*>([^<]+)<\/title>/)[1];
				//$('head title').html( title );

				//console.log("TITLE = " + title);
				
			  //if browser doesn't support CSS transitions - dont wait for the end of transitions
			  var delay = ( transitionsSupported() ) ? 30 : 0;
			  setTimeout(function(){
				$('body').removeClass('page-is-changing');
				$('.cd-cover-layer').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
				  isAnimating = false;
				  $('.cd-cover-layer').off('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend');
				});				
				
				ga('set', 'page', '/' + url);
				ga('send', 'pageview');
				
				FirstLoad();
				HeroSection();				
				Sliders();
				FullPage();				
				MasonryPortfolio();
				LazyLoad();
				HideShowHeader();
				FooterAppear();				
				Lightbox();
				AppearIteam();
				BackToTop();
				ContactForm();
				CollagePlus();
				PageShare();
				PageChat();		
				
				
				if( !transitionsSupported() ) isAnimating = false;
			  }, delay);			  
			  if(url!=window.location && bool){
				window.history.pushState({path: url},'',url);
			  }
				});
		  }

closed #6

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.