Quantcast
Channel: SharePoint 2010 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 17574

Why JavaScript is not working in HTML Editor

$
0
0

Hi all,

I have a SP 2010 Page where it has 5 images in a table. I need to open those images in a new tab based upon which one is clicked. I thought of going with javaScript as it is simple and prepared script as follows

<title>This is a Test page for JavaScript</title><script type="text/javascript">
        function myfunction(e) {
            alert("got the Id as"+e);
            var k = document.getElementById(e).getAttribute("src");
            alert(k);
            window.open(k);
        }        </script></head><body><img  alt="klsdls" id="myImage" src="http://chefshelpingchefs.com/wp-content/uploads/2012/01/training-image.jpg"  onclick="myfunction(this.id);" title="Click to see an enlarged Image"/><img  alt="klsdls" id="Img1" src="src1"  onclick="myfunction(this.id);" title="Click to see an enlarged Image" height="50px" width="50px"/><img  alt="klsdls" id="Img2" src="src2"  onclick="myfunction(this.id);" title="Click to see an enlarged Image" height="80px" width="50px"/><img  alt="klsdls" id="Img3" src="src3"  onclick="myfunction(this.id);" title="Click to see an enlarged Image" height="100px" width="50px"/><a href="" onclick="myfunction(img1)"></a></body>

It works fine on the Normal HTML Page( I created one using Visual Studio) but when I try to insert the same javascript in SP 2010 Page I have,

The Java Script function I typed in the HTML editor is not showing up once I click save.

hence javascript is not working as expected. Later when I open the page to edit the HTML, the Script tag including the javascript function is disappeared and also the onclick attribute of the image sis not showing up.

What is this weird behavior of SP 2010 in handling java Script and onclick events for images?


K.V.N.PAVAN


Viewing all articles
Browse latest Browse all 17574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>