Calling a javascript file off domain?

Discussion in 'JavaScript' started by matrocka, Aug 11, 2010.

  1. #1
    Hi All:

    I'm trying to write a wordpress plugin that incorporates baseball-reference.com's B-R Linker (http://www.baseball-reference.com/linker/) functionality with my wordpress installation (if you follow the link - the B-R Linker is currently just a bookmarketlet - I want to have it ran automatically when hitting submit); however it does not seem to be working:

    I tried to bind the javascript code to the "Submit" button on Wordpress to no avail; however if I replace the sr_link function's code with 'alert("Testing");' it works - I believe it may be an intentional "defect" of javascript to not allow running off domain scripts. If this is the case - is there any way to get around this? or can anyone tell if I am doing anything wrong? Thanks so much.

    -MS

       function sr_link() { 
           var s=document.createElement("script");
           s.charset="UTF-8";
           var rand_param =    "rand=" +  Math.floor(Math.random()*10000);
           s.src="http://baseball-reference.com/linker/linker.js?"+ rand_param;
           void(document.body.appendChild(s));
       }
    
    
     jQuery(document).ready(function() {
        
        
        jQuery('#publish').bind('click', function() 
          {
          jQuery("#edButtonHTML").click();
          sr_link();  
        
        
          }); 
      });
    
    Code (markup):
     
    matrocka, Aug 11, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Does it alert "Testing" in this case:

    
    function sr_link() { 
           var s=document.createElement("script");
           s.charset="UTF-8";
           var rand_param =    "rand=" +  Math.floor(Math.random()*10000);
           s.src="http://baseball-reference.com/linker/linker.js?"+ rand_param;
           alert("Testing");
       }
    
    
     jQuery(document).ready(function() {
        
        
        jQuery('#publish').bind('click', function() 
          {
          jQuery("#edButtonHTML").click();
          sr_link();  
        
        
          }); 
      });
    
    Code (JavaScript):
    If no, what error it shows?
     
    s_ruben, Aug 12, 2010 IP