function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
a contratora contrator 

run JavaScript in sidebar

Why my javascript does not work ?

 

Here is what I tested:

 

(1) create a custom component 'test' ---type:  HTML Area, ticked "show HTML",  content:   <script> alert('testing....);</script>

(2) add this component to my default home page layout

(3) check "show custom sidebar components on all pages"

 

(4) click on any TAB,  the component only display the name "test" on the sidebar, no javascript running

(5) same thing if the javascript is like

<script>

function init() {
   alert("testing...");
}
window.onload = init;

</script>

 

Any help will be greatly appreciated.

Chamil MadusankaChamil Madusanka

try this approach

 

<apex:page >
  <script src="http://code.jquery.com/jquery-1.7rc2.js"></script>
  <head>


<script type="text/javascript"> 
$(document).ready(function(){

    $("#one").slideDown("slow");
   
});
$(document).ready(function(){
$("#pOne").click(function(){
    $("#one").slideToggle("slow");
    $("#two").slideUp("slow");
  });
});
$(document).ready(function(){
$("#pTwo").click(function(){
    $("#two").slideToggle("slow");
     $("#one").slideUp("slow");
  });
});
</script>

<style type="text/css"> 
div.panel,p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e4f8ff;
border:solid 1px #c3c3c3;

}
div.panel
{
height:auto;
display:none;
}
</style>
</head>

<body>
 <p id="pOne" class="flip">Test 1</p>
<div id="one" class="panel">
<apex:form >
  <apex:pageBlock >
  
       <apex:pageBlockSection >
           <apex:outputText value="Panel 1"></apex:outputText>
       </apex:pageBlockSection>  
       
  </apex:pageBlock>
  </apex:form>
</div>
<p id="pTwo" class="flip">Test 2</p>
<div id="two" class="panel">
  <apex:form >
      <apex:pageBlock id="UnitApprovalBlock">
          
          <apex:pageBlockSection >
              <apex:outputText value="Panel 2"></apex:outputText>
           </apex:pageBlockSection> 
           
  
     </apex:pageBlock>
  </apex:form>
</div>
</body>
</apex:page>

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

a contratora contrator

Thanks Chamil.

 

In your solution, a VF page will be created to handle the javascript which does not meet my needs.  What I am going to implement is to hide some button / link in some standard page layout, ex:   "add to invitees' in event edit page layout.  Using a common JavaScript in a custom home page component  is a good resolution as mentioned in this board before.  My problem is I don't know why it does not work for me based on my test.

dfpittdfpitt

Hi,

 

where you able to run javascript in a sidebar component?

 

I'm trying as well, with no luck.

 

Daniel