This is my js code :

<script type="text/javascript">

var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;
var pngPath = '/_catalogs/masterpage/assets/tools-banner.jpg'; 
var elem = document.createElement("img");
elem.src = url + pngPath;
elem.setAttribute("alt", "Banner");


when i test it in the browser console it work just fine , but when i put it in the of my master page it doesn't work should i load jquery? any solution ?


1 Answer 1


Did you end the script with tag? better copy your code in a text file ( remember not to add tag in the text file, just the code) and save it as .js file. Load the file in Style library and publish it.

Now in Master page add script tag <script type="text/javascript" src="link where javascript is loaded"></script>


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.