简体   繁体   中英

I cannot load javascript

We've been doing my little mail project and I've encountered some problems.

I've been using tomcat and apache so I use jsp right now.

My problem is that I cannot load js file with tag in jsp file. We want to make kind of single page application so some jsp files are calling other jsp files.

Our jsp file structure is constructed like this way.

box.jsp -> mail-list.jsp -> (select mail from mail list, get mail content to communicate with server, append at the bottom of the list and swipe it with animation to show mail contents) -> detail-mail.jsp

In box.jsp, tags are working so I can load java scripts and use it because box.jsp(mail list viewer) shows mail list and all of our java script files are loaded at box.jsp.

But in detail-mail.jsp(show detail mail contents and etc), It doesn't work even though 'detail-mail.jsp' has tags.

Even though css files are loaded, java script files aren't.

Is there any way I can load java script file in this situation?

If I understand correctly: Are you trying to load script tags in an e-mail?

I'm not familiar with JSP, but I have done a fair bit of e-mail development.

You cannot use JavaScript in e-mails, unfortunately. So maybe the <script> tags are being removed from the output of detail-mail.jsp ?

You should use these code if you want to load javascripts dynamically with append child.

    const s = document.createElement('script');
    s.type = 'text/javascript';
    s.src = '/js/detail-mail.js';
    $('head').append(s);

If you load html after javascripts, javascripts cannot figure out DOM ELEMENTS. So you should load HTML and after that, you shoudl load javascripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM