• What up yall!

    got a javascript question for all you smart people w/ sexy brains.

    I am trying to move a bit of JS from inline (i have it inserted into a wordpress post) to an existing external file that I call in.

    However– my code must require some kind of formatting changes or something- because it no longer works when I put it in the external file (the rest of the existing JS in that external file continues to work fine– however)

    Anyone got ideas on what I need to change?

    Here is my JS (this works inline):

    <script type=”text/javascript”>// <![CDATA[
    document.getElementById(‘FBsharer’).onclick = function () {
    var url = ‘https://www.facebook.com/sharer/sharer.php?u=&#8217;;
    url += encodeURIComponent(location.href);
    window.open(url, ‘fbshare’, ‘width=640,height=320’);
    };
    // ]]></script>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The problem is most likely to be that you’re Javascript is executing before the element that you’re targeting has been set up by the browser.

    The standard way to get around this is to wrap that code in a jQuery wrapper to make sure that the DOM has been set up correcdtly. As an example…

    jQuery (document).ready (function () {
    
        // Put your code in here.
    
    });
    Thread Starter pvijeh

    (@pvijeh)

    thanks ill give that a shot!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Moving Javascript from inline to an external file’ is closed to new replies.