inline javascript not running on salesforce site

  • 2
  • Problem
  • Updated 1 year ago
  • In Progress
This inline javascript:

(function(skuid){
var $ = skuid.$;
$(document.body).one('pageload',function(){
   console.log('Page Loaded');
});
})(skuid);

When I run the page with the skuid preview, it works fine. When I run it visual force on a salesforce Site, the code doesn't execute and my console is blank.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 1 year ago

  • 2
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
I'm on skuid 8.15.15
Photo of Pete O'Connell

Pete O'Connell

  • 214 Points 100 badge 2x thumb
$(document.body).one(

should be 

$(document.body).on(
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Pete. Neither works.
Photo of Pete O'Connell

Pete O'Connell

  • 214 Points 100 badge 2x thumb
try:

$(document).ready(function() {
    console.log("hello world");
});
Photo of Pete O'Connell

Pete O'Connell

  • 214 Points 100 badge 2x thumb
try

$(document).ready(function(){
    console.log('page loaded');
});
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
No, the problem is not the ready function itself. The problem is that the script isn't being called at all.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Skuid-- any ideas on this?

I have an inline javascript resource like the following, which runs fine in salesforce but on on a salesforce site:

(function(skuid){
    console.log('script loaded');
})(skuid);
Photo of Amy Dewaal

Amy Dewaal, Official Rep

  • 8,200 Points 5k badge 2x thumb
Matt,

Try using $(".nx-page").one("pageload",function() { instead of $(document.body).one('pageload',function(){ - oh, just realized you said the snippet isn't getting called at all, so that won't help you. Do you see any errors in the browser console?
(Edited)
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
No errors in the console.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Is there something about force.com sites that I need to do differently? Is there some kind of security setting that could be getting in the way?

Searching through the salesforce documentation and forums hasn't gotten me anywhere.