Click to See Complete Forum and Search --> : window.location problem
Lilly07
02-11-2008, 02:36 AM
I have no idea whether this question is to be raised here or in any javascript forum.
I just tried with the following example:The first one works:
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
function function2() {
window.location = "http://www.mozilla.org";
}
</script>
<f:view>
<html>
<body>
<form>
<input type="button" value="Check Status" onclick="function2();">
</form>
</body>
</html>
</f:view>
When I am trying to use JSF as belwo, windows.location doesn't work
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
function function2() {
window.location = "http://www.mozilla.org";
}
</script>
<f:view>
<html>
<body>
<form>
<h:panelGrid>
<h:commandButton value="checkStatus" onclick="function2()"/>
</h:panelGrid>
</form>
</body>
</html>
</f:view>
What might be the problem?
Lilly07
02-11-2008, 03:13 AM
I tried that too. Still unable to make window.location work.
It works for me in a simple HTML document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function function2() {
window.location.href = "http://www.mozilla.org";
}
</script>
</head>
<body>
<form>
<input type="button" value="Check Status" onclick="function2();">
</form>
</body>
</html>
Lilly07
02-11-2008, 03:29 AM
that is right! it works perfectly fine in html. I am using JSF. When view page source is clicked, I get the following code. Any clue from that.
<script type="text/javascript">
function function2() {
window.location.href = "http://www.mozilla.org";
}
</script>
<html>
<body>
<form id="myForm">
<table><tbody><tr><td><input id="_id1" name="_id1" type="submit" value="checkStatus" onclick="function2();clear_linkDummyForm();" /></td></tr>
</tbody></table>
</form>
</body>
</html>
<form id="linkDummyForm" name="linkDummyForm" style="display:inline" method="post" action="/elm2/test.html"><input type="hidden" name="jsf_tree_64" id="jsf_tree_64" value="H4sIAAAAAAAAAIWPPU7EMBCFZ0MWASULFSClpEAO1FT8SOxKASH+Whg53o2RYxt7whoKJA5BQcENuAc99+AOOOwKIYRE84qZ972Z 9/oBXe8g46ZmvtFsiFx41pBU7MwJcUqu4dQ4sTRc2V99usoSSAuY45VUpROaYLm4xlvMWyDfcQ7vCulpu4B5rtD7I6wFweLEo1CP8h go9SgaZttL5Al6PxL66KtDtHGdyPIGHiAJNn7Xax2Tp75vhMf3tec3fJmBzgBSL+9FsADQGadRF3wLw5d2f08twUYbGKZlY3VrdC zDKqoV60fZM3WNutxtiIyO/vRSlluBYP0f7hi1UAdOllNmMzLZ38z54EKK8YkxZO0nb3reZ4UBAAA=" /><input type="hidden" name="jsf_state_64" id="jsf_state_64" value="H4sIAAAAAAAAAIVSv2/TUBA+u86PJkVKUomJqB0Y6OK0TEgdoCktteQkKEkBwZC+OK+Jg2ub986Jy1C1CwwsDDAgFcHA2H8CMTCBBBILE2IGVn4s4GcSJ4Q Kbjjde3fv7rvve0efIeYxmL2hd0mPqBax22ql2aUGLt9/fe1Jhi9YMoDvAoDs3YI9EKZEUZIzyIYvPTQtdYPwTom4scT75y9Obr2ZAnkdUpZDWuvEQIdpMI0dRnnHsVq+e/5C2GKmnwx8RgxAOC16+eo2MShX+7RJXFdd3axW18r1xhVt7WqjWqnUxfA4wvxxtZXS5UpZVGsXawG22RG2FcbIrm5y9A/e5h+9JI+nQNJA4eZtGq4n9ZXApxCUhtla9H3XdaPlQlqKjmNRYr+aZ/vvDn98kUG6DrEesbzgvcQFqDS4LkJqo17SG8WVmraKMF1AylHtctEsM0KjOwax6N637Nbh4vdPMigaJDsBe4bTojokDMezke0i5E JdCgJAoYbMtNvLOiTF0SNtKoZmg/IeYSaxMTz67s/AEOTNWuCojQCRXFIUjcScGxNTRMpfukjiOhEmk5NELQVEDSgT+ZRwM8KdwN/rDgW6xMzWJKOajbRNWe7j02dfD+6ek4UgA0aHZIV1ZW+nSdmdo4f59IMP98L/uB9ACMcImUQwN35zjP2Tg3wUxf/LBgwXXhL5U+ML58YXLnqIjh1MDpODirTRocbNGhL0+B8pATFIb3u2gaZjnz2zMIZ9sizOveaOiRFU+AUyZe3wxgMAAA==" /><input type="hidden" name="jsf_viewid" id="jsf_viewid" value="/test.jsp" /><input type="hidden" name="linkDummyForm:_link_hidden_" /><script type="text/javascript"><!--
function clear_linkDummyForm() {
var f = document.forms['linkDummyForm'];
f.elements['linkDummyForm:_link_hidden_'].value='';
f.target='';
}
clear_linkDummyForm();
//--></script></form>
your document is not HTML correct formatted. You must not have anything outside the <html></html> except the DOCTYPE. And you need a DOCTYPE.
That means your generated document should keep the construction:
DOCTYPE ...
<html>
<head>
... <script type="text/javascript"></script> ... here
</head>
<body>
... HTML elements here ...
</body>
</html>
poojasreejith
02-11-2008, 07:39 AM
Try using windows.location.href rather than windows.location . This might help.
Lilly07
02-11-2008, 10:41 PM
This function works perfectly fine when I tried testing like below:
<body onload="function2()" >
Why it is not working when i use onclick as below:
<h:commandButton value="checkStatus" onclick="function2()" />