Forum Discussion

Han's avatar
Han
Ace
6 years ago

Jquery Uncaught TypeError

Hi all,

I'm trying to update the functionality for the print page functionality.

My code is: 

	<@liaAddScript>
  ;(function($){
    <#-- print button to open in new window-->
    $('.lia-component-forums-action-print-message').on('click', function(e) {
      e.preventDefault();
      window.open(this.href, "_blank", "toolbar=yes,top=0,left=0,width=800,height=600");
    });
  })(LITHIUM.jQuery);
	</@liaAddScript>


But I am I currently getting  an error saying: 

lia-scripts-head-min.js:3 Uncaught TypeError: Cannot read property 'setAttribute' of null
    at Object.init (lia-scripts-head-min.js:3)
    at 1:1093
init @ lia-scripts-head-min.js:3
(anonymous) @ 1:1093


I have not added in a JQuery library, because it's my understanding that a version of the library is built into lithium. 

Is there something I am missing? 

 

  • Han As you can see from the error message, the error is not coming from you, it is coming from a native Lithium js file which you have no control over, e.g. 

    lia-scripts-head-min.js

    so you might have to contact support about this... 

  • Han,

    Your code seems to me working perfectly fine. Is there more information you can share on this. After looking into the error you have shared above is not due to the print jQuery code you have added the latest.

    Cannot read property 'setAttribute' of null

    Its the separate function which you are using to setAttribute which cause due to the empty variable found.

     

    • Han's avatar
      Han
      Ace

      Parshant,  I've tested with all other JS removed, and I am still getting the error. There is also nowhere in any code I have added in where I am attempting to use "setAttribute".

      Oddly enough, my block of jQuery above is working today. I would still like to know what the error is, as it seems to cause unpredictable behaviour with my js functionality. 

      • luk's avatar
        luk
        Boss

        Han As you can see from the error message, the error is not coming from you, it is coming from a native Lithium js file which you have no control over, e.g. 

        lia-scripts-head-min.js

        so you might have to contact support about this...