Blogger Forums » Blogger Widgets

script event does not work in the rich editor when writing a new post

(4 posts)
  1. remi

    new member
    Joined: Dec '11
    Posts: 2

    I wrote the following code:

    <span id="spanID">
    hello world
    </span>

    <script type="text/javascript">
    document.getElementById("spanID").onclick = function(){alert('yes');}
    </script>

    I tested the code in a html page and it worked, but when I put the code in the "edit HTML" tab in the new blog page it didn't work, and the onclick event didn't ocuur when I clicked on the "hello world" text in the compose tab. why?

    Posted 1 month ago #
  2. aneesh

    site admin
    Joined: Jul '09
    Posts: 232

    can you show me a link where you some JavaScript Code which is not working?

    It should be due to the automatics line breaks that blogger inserts into your posts. So you can try writing the entire JavaScript snippet in a single line
    eg:
    <script type="text/javascript">document.getElementById("spanID").onclick = function(){alert('yes');}</script>

    The Blogger Settings have some option to prevent automatic line breaking.You can try that as well

    Posted 1 month ago #
  3. remi

    new member
    Joined: Dec '11
    Posts: 2

    thanks for the reply. But it's still not working.

    I even tried to write the following code in the "edit html" tab:

    <span id="spanID" onclick="alert('yes');">
    hello world
    </span>

    I clicked on the compose tab and again on the edit html tab and the script event just deleted! the code which left was:

    <span id="spanID">
    hello world
    </span>

    why is it deleting my code?

    Posted 1 month ago #
  4. aneesh

    site admin
    Joined: Jul '09
    Posts: 232

    you might have noticed that if you don't switch back to compose mode then the scripts stay

    Posted 1 month ago #

RSS feed for this topic

Reply

You must log in to post.