• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

problem with importing importing external .js in jsp

 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, the external javascript file, won't be imported when I try that between <head/> tag. Simply, it is ignored. If I try to import it at the begin of <body> tag, it has been partially imported and still have no access to id's of the elements of the page. Only when I put import statement just before closing </body> tag, everything works fine.
However, I need that javascript file to be loaded before the entire page is rendered, so I need to put .js at first two mentioned places. What is the problem?
I am using xhtml doc type
thanks!
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have googled and try many things like this :
- to use, withininside <head> element , it won't working.
- I have also tried to navigate to my .js file using form:, but still, it won't wokr
Does anyone have an idea what could be???
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

However, I need that javascript file to be loaded before the entire page is rendered,



Why at the beginning?
What is this javascript doing?
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hide certain elements of page, which are consequently revealed at appropriate event.
But this way, first all elements are loaded and displayed on the page, and when page loading reach script files at the end of the <body> it hide it. But the disarrangement of elements first appears for a second/two. Pretty much "stabbing needle" in my eyes!
Why scripts are not loaded in the <head> element, or right after opening <body> tag?
In the same html, external css file are successfully loaded in <head>tag, which is bothering me more...
 
James Ward
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the javascript would indeed be loading if you put it in head tag or before body tag in the beginning, but it wont be able to 'act' on any 'elements' in your html document until they are loaded - therefore it appears that javascript is not working/or not loading.

And this is the reason it works if you put it at the end of body tag.

One thing you can try is, modify the javascript to put whatever code is executing on load, inside a function. Then call this function from onload event of the body tag. <body onload='myfunction()'>.


 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do have initialized function which is called in js and its does purpose. Never mind, I would do manually (positioned all elements out of view, and on subsequent call preform original position). Ok with that, but why imported js won't work at placed they suppose to run (inside <head> tag and at the begin of <body> tag)?
Why?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry our magic balls are all in the shop being repaired. Without seeing your code or your magical error messages that is produce we can not help you out.

Eric
 
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is covered in the JSP FAQ. You need to use a server-relative URL.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a quite large js and html, and there is no interest to present all. This is a segment. When I link to js from head you'll get irregularity , if you link to js from end of the body, its ok.
html :



JS file (part important to this element) imported by <script type="text/javascript" src="sler_library.js"></script>


Later on some event, the text block should be arranged to be seen. And that part works. But as you see, if js file is imported in <head> or at begin of <body> file, it is undesirable shown. If you put it on the end of <body> tag, it is hidden, just as I wanted, guitext.style.display = "none";, and latter I will easy show him. So why the library won't to be loaded?
 
Bear Bibeault
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are not going to read replies, why should anyone respond?

I have already answered your question.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Bibeault, but I didn't see your response thanks , but I tried also...
 
Bear Bibeault
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the JS file is where it should be, then there is no way that a correct server-relative URL will not correctly address it.

Either your URL is not matching the file location, or the problem is not as you think.
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this to put as a link to js (I also change folder name):


Where javas is folder name of js file, and app_name is root folder of application. None of the above won't work when its put in <head> or an begin of <body> element.
 
Bear Bibeault
Sheriff
Posts: 67642
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then the path to the web application or file cannot be correct.

What happens when you type http://localhost:8080/app_name/javas/sler_library.js directly into the browser?
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got js file displayed. It find it correct. I am not clever any more
reply
    Bookmark Topic Watch Topic
  • New Topic