CSS and Javascript missing in one of two almost identical pages - javascript

Good afternoon StackOverflow, I have two almost identical pages:
Once deployed one of the Pages (Login.xhtml) loads everything correctly:
But the other page (Index.xhtml) doesn't import some of the CSS and JS:
I am confused as to why this would happen.
The elements themselves have identical formatting, this is one of the files being called (Login.xhtml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" >
<body>
<ui:composition>
Login Content
</ui:composition>
</body>
</html>
And here's the other (content.xhtml)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough" >
<body>
<ui:composition>
content Content
</ui:composition>
</body>
</html>
Any clue as to why this is occurring? I just can't wrap my head around it, any and all help would be greatly appreciated.
Edit: Further information, both Index.xhtml and Login.xhtml (The composition files) are in the same folder.
The resource files Login.xhtml and content.xhtml are both in the same folder as well.

Can you add the links manually do your Login.xhtml? When this is working it may depens on the controller.
Edit: Sorry saw your post to late.
Did you try to check there in the same folder and they work well to include them manually in your Login.xhtml?
Are the paths correctly means are login and index are in the same folder?

Found a solution to my problem.
The problem of the missing Javascript and CSS libraries was due to the lack of Primefaces elements in the content.xhtml.
I fixed this by adding a Growl:
<p:growl id="growl" showDetail="true" sticky="true" />
That doesn't display, to the file common.xhtml. While I was properly importing Primefaces jQuery using the line:
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
Some of the scripts required other libraries that automatically import with Primefaces elements.
This may not be the elegant solution, but it became a solution that solves my issue nonetheless.
Good day, and thanks for your help.

Related

external CSS files are not loading all the time in IE 11. But when i hard refresh the page its loading. how to fix this issue?

external CSS files are not loading all the time in IE 11. But when I hard refresh the page its loading. Is there any way to ensure External CSS files load properly in IE 11 browser
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:composition>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<script type="text/javascript" src="path/to/css/css-min.js"></script>
<link rel="stylesheet" type="text/CSS" href="path/to/CSS" />
this is how I included CSS files.
If a hard refresh will make them work, that means your external CSS files are getting cached in the browser and they may not get updated from time to time. You can try specifying the version number of a style sheet to force the browser to update CSS. For example:
<link rel="stylesheet" type="text/css" href="styles.css?version=2">

External scripts not working in Windows Phone App 8.1

I've added a WebView into my project. If I navigate to the html file that contains external javascript files they don't work. Bit if I write the javascript code hardcoded into the html file it works properly.
Here is the html portion:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="testjs.js"></script>
</head>
<body>
<div id="abcd"></div>
<br/>
hello! this is a simple html block.
</body>
</html>
Here is the javascript portion:
document.getElementById("abcd").innerHTML = "New text!";
When I open the webview it shows
hello! this is a simple html block.,
but if the javascript code worked it would show
New Test!
hello! this is a simple html block.
Here is the folder structure:
src="testjs.js" is correct. The issue is not related to the path.
[Update 1]
Your code should work as we usually do for web development. But seems we need to make sure the html element used in the script has been initialized, so we have to put the to the end of the body element. Please try the following html code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="abcd">a</div>
<br />
hello! this is a simple html block.
<script type="text/javascript" src="testjs.js"></script>
</body>
</html>
[Update 2]
Also check if you have changed the build action for testjs.js to content. go to Solution Explorer -> right click on testjs.js -> Properties -> change Build Action to Content. That will make sure the .js file will be deployed as part of you app.
WebView msdn page suggests that for security reasons you can not link to local content except for:
However, you can still link to HTML content in the app package using the ms-appx-web scheme, and to web content using the http and https URI schemes.
So you should be able to link to your script file using ms-appx-web:///testjs.js url.

JavaScript Failure

I try to learn how to write Javascript but I have found a problem either so basic I would never think about it or so complicated that I lack the knowladge to find it.
I am Using NetbeansIDE 8.0 .
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<title>Objekt Navigator</title>
</head>
<body>
Something<br/>
<script language="javascript" type="text/javascript">
document.write("Text");
alert("Bla bla");
</script>
Else<br/>
</body>
</html>
If the compiled page is opened it will only display "Something" and "Else" but nothing of the script.
If I remove "document.write("Text");" it will show the alert but there is no wrong wording in "document.write".
I really need one (or more) pointers to understand this.
Pointer 1:
Don't use document.write. Really. It has been archaic and obsolete for at least 15 years, if not 20. Use regular DOM methods.
Whatever tutorial you found that in, choose something else.
Pointer 2: Don't use XHTML. Use the HTML5 Doctype. The XHTML one does some very weird things with JavaScript -- IF the file is being served as XHTML.
Lastly: your code works just fine for me. If this is not the exact code that you are using in your tests, look at your console.log to see if you have an error somewhere.

Targeting JS named opening window in Safari?

I have a static HTML page which is named via JavaScript as such: window.name = "windowname". This window opens a popup window, which contains links that target windowname.
This works as expected in IE/FF/Chrome and opens the links on the opener, however, Safari opens all links in a new window and not the opener.
Is anyone aware of a workaround or solution to this other than using JavaScript to open the links via opener.location.href? Is this a security feature of Safari or some other kind of issue?
Thanks in advance
Trying setting the "id" attribute to the same string as the name.
Not 100% sure what you problem is without being able to see your code but the following worked for me in Safari 4:
windowname:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
</head>
<body onload="window.name='windowname'">
Open
</body>
</html>
popup:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
</head>
<body>
test
</body>
</html>
No resolution for this was ever found, I had to go with a method that didn't use pop-up windows due to this.
thanks for the effort.
b

Download Javascript generated XML in IE6

I'd like to use Javascript to make IE6 download a file. It'll be created on the fly using Javascript. This file doesn't exist on a webserver. Here's a small example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function clicked() {
var xml = "<data>Just for testing</data>";
document.open("text/xml", "replace");
document.write(xml);
}
</script>
</head>
<body>
<input type="button" value="Download" onclick="clicked();" />
</body>
</html>
Instead of loading the xml in the browser window, I want it to cause IE6 to prompt the user where to download the data to so that it can be saved without them having to use File -> Save as. Any ideas?
For IE6 you should be able to use document.execCommand() after your document.write():
document.execCommand('SaveAs',true,'file.xml');
This is not part of any standard and will only work in IE flavor browsers.
If your data must be generated client side, then you can post it back to the server so that it can be returned as a downloadable file.
No, this is not possible. A web-browser strictly doesn't allow this, as the ability to save files to disk through JavaScript only, would be very dangerous, even if the confirmation popup shows up.
EDIT: Thanks to other answers, I found out (not surprisingly) that this behavior is possible with some versione of IE.

Categories

Resources