Borja
Borja

Reputation: 3551

google.load only if specific page?

i have this:

google.setOnLoadCallback(googlata); //googlata() is a function to create a google cse
google.load('search', '1'); 

I want to run the top code only if the page opened is

www.example.com/example

i tried with this:

var paginaricerca= self.location.href;
var Searchpage= paginaricerca.indexOf('example')+7; 
var urlpage= paginaricerca.slice(0,Searchpage);
if(urlpage=='www.example.com/example'){
     google.setOnLoadCallback(googlata); 
     google.load('search', '1');    
}

but doesn't work....

is there an another way ?

thanks a lot !!! :)

Upvotes: -2

Views: 32

Answers (1)

Carlos Sultana
Carlos Sultana

Reputation: 709

location.href gives you the current url, not sure what you are trying to do with the slicing but you should be able to compare it to a string of the url you want to check

var paginaricerca = self.location.href;
var urlCheck = 'http://example.com/example';

if (paginaricerca === urlCheck) {
     google.setOnLoadCallback(googlata); 
     google.load('search', '1');    
}

Upvotes: 0

Related Questions