Tuesday, July 31, 2012

Need help getting the name of a included jsp page in javascript



I have this code for a .jsp page:



<f:view>
<div class=\"portletBody\">
<h:form id=\"editSectionForm\" onsubmit=\"return numCheck(document.forms[0].elements[\'editSectionForm:sectionTable:0:maxEnrollmentInput\'].id)\">




<sakai:flowState bean=\"#{editSectionBean}\"/>

<t:aliasBean alias=\"#{viewName}\" value=\"editSection\">
<%@ include file=\"/inc/navMenu.jspf\"%>
</t:aliasBean>

<h3><h:outputText value=\"#{msgs.edit_section_page_header}\"/></h3>

<%@ include file=\"/inc/globalMessages.jspf\"%>

<t:aliasBean alias=\"#{bean}\" value=\"#{editSectionBean}\">
<%@ include file=\"/inc/sectionEditor.jspf\"%>
</t:aliasBean>

<t:div styleClass=\"act\">
<h:commandButton
action=\"#{editSectionBean.update}\"
value=\"#{msgs.update}\"
styleClass=\"active\"
onclick=\"reEnableLimits();\" />

<h:commandButton action=\"overview\" value=\"#{msgs.cancel}\" immediate=\"true\" />
</t:div>
</h:form>
</div>
</f:view>


and I have some javascript code that runs in the /inc/sectionEditor.jspf file. In some of that code in the sectionEdtior file, I need to somehow grab the id of this form. editSectionForm. I can\’t hard code it because the /inc/sectionEditor.jspf code runs in more than one page.


So pretty much, I need the javascript code in /inc/sectionEditor.jspf to be able to grab the id of the form it is currently in.


i.e:


If I\’m in the editSectionForm page, it\’ll tell me that im in that page, if I\’m in addSection Form page, it\’ll tell me that I\’m on that page.






Rating: 2 out of 5 based on 3 ratings



The post Need help getting the name of a included jsp page in javascript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/need-help-getting-the-name-of-a-included-jsp-page-in-javascript.html

javascript – getting the inner text of a node



I am having trouble getting the inner text of a particular node. I have added the example node I am working with and the javascript I have come up with. The javascript works as far as returning this <span id=\"goal_left\">3 goals lect</span> if i log it to the console. If i add innerText to the javascript examples it will return nothing to the console. Any ideas how to get this text?


html



<span id=\"goal_left\">3 goals lect</span>


javascript: these examples return <span id=\"goal_left\">3 goals lect</span>



document.getElementById(\"goal_left\");

document.querySelectorAll(\"span#goal_left\")[0];


javascript: these examples return nothing



document.getElementById(\"goal_left\").innerText;

document.querySelectorAll(\"span#goal_left\")[0].innerText;






Rating: 3 out of 5 based on 3 ratings



The post javascript – getting the inner text of a node appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-getting-the-inner-text-of-a-node.html

jquery – How to call ajax only once



I call function from this code :



<div id=\"header-button-news\" class=\"header-button-info\">
<a href=\"javascript:;\" title=\"Новости\" onclick=\"showNews()\"></a>
<div class=\"new\">2</div>
</div>


My function is



function showNews()
{
//other js which show block

jQuery(\"#loader\").show();


//ajax which load content to block
jQuery.ajax({
type: \"GET\",
url: link,
dataType: \"html\",
success: function(data) {
jQuery(\'#top-info-news\').html(data);
},
complete: function(){
jQuery(\'#loader\').hide();
},
});
}


How can I make only once ajax call? so when content is loaded and page was not refresed not to load ajax? I tried to do boolean variables but nothing, I suppouse it is because I call everytime function. Please give me an idea how to do.


thank you






Rating: 1 out of 5 based on 3 ratings



The post jquery – How to call ajax only once appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-how-to-call-ajax-only-once.html

javascript – Why does it print only one time? Please give me solution




<html>
<head>
<script type=\"text/javascript\">
function printpage()
{document. getElementById (\'print\').style.display=\'none\';
window.print()
}
</script>
</head>
<body>
<td align=\"center\">
<input name=\"print\" type=\"submit\" id=\"print\" value=\"PRINT\" onclick=\"printpage()\" />
</td>
</body>
</html>


When I click, it will open a print window.

Once I close print window and open it again and then click on print, without reloading, then it will not work.






Rating: 3 out of 5 based on 3 ratings



The post javascript – Why does it print only one time? Please give me solution appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-why-does-it-print-only-one-time-please-give-me-solution.html

tags – how should my site handle ocassionally missing javascript files gracefully?



Say I\’ve got this script tag on my site (borrowed from SO).



<script type=\"text/javascript\" async=\"\"
src=\"http://edge.quantserve.com/quant.js\"></script>


If edge.quantserve.com goes down or stops responding without returning a 404, won\’t SO have to wait for the timeout before the rest of the page loads? I\’m thinking Chaos Monkey shows up and blasts a server that my site is depending on, a server that isn\’t part of a CDN and has a poor failover.


What\’s the industry standard way to handle this issue? I couldn\’t find a dupe on SO, maybe I\’m searching for the wrong terms.


Update: I should have looked a bit more closely at the SO code, there\’s this at the bottom:



<script type=\"text/javascript\">var _gaq=_gaq||[];_gaq.push([\'_setAccount\',\'UA-5620270-1\']);
_gaq.push([\'_setCustomVar\', 2, \'accountid\', \'14882\',2]);
_gaq.push([\'_trackPageview\']);
var _qevents = _qevents || [];
(function(){
var s=document.getElementsByTagName(\'script\')[0];
var ga=document.createElement(\'script\');
ga.type=\'text/javascript\';
ga.async=true;
ga.src=\'http://www.google-analytics.com/ga.js\';
s.parentNode.insertBefore(ga,s);
var sc=document.createElement(\'script\');
sc.type=\'text/javascript\';
sc.async=true;
sc.src=\'http://edge.quantserve.com/quant.js\';
s.parentNode.insertBefore(sc,s);
})();
</script>


OK, so if the quant.js file fails to load, it\’s creating a script tag with ga.async=true;. Maybe that\’s the trick.


Possible answer: http://stackoverflow.com/a/1834129/30946






Rating: 1 out of 5 based on 3 ratings



The post tags – how should my site handle ocassionally missing javascript files gracefully? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/tags-how-should-my-site-handle-ocassionally-missing-javascript-files-gracefully.html

html – Extract part of inner text from a div using jquery



How do i extract the text part of a div leaving out text of inner html tags


Here is the div



<div class=\"MessageBox\">I want to see only this message<span....>Click Here to collapse</span></div>


Here is the jquery inside a javascript function



var message= $(\".MessageBox\").text();


Right now i am getting

message= \”I want to see only this message Click Here to collapse\”


I want message =\”I want to see only this message\”






Rating: 4 out of 5 based on 4 ratings



The post html – Extract part of inner text from a div using jquery appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/html-extract-part-of-inner-text-from-a-div-using-jquery.html

php – saving variable value and retrieve it after page refresh



I have a string value saved in to a variable, my webpage auto reloads after a certain process.. I need to know if I can get the value stored in that variable even after page refresh?


Im refreshing my web page using javascript code window.location.reload()


If not will it work if I take to server side script like php?






Rating: 4 out of 5 based on 6 ratings



The post php – saving variable value and retrieve it after page refresh appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-saving-variable-value-and-retrieve-it-after-page-refresh.html

jquery – Running Javascript after CSS is fully loaded



I have some code that depends on the css being loaded.


I load css on the header before I load the javascripts on the footer




$(window).load
bar_position = $(\'body\').height() - 38 #38 is the size of the bar
width = $(\'body\').width()
console.log(bar_position)
if (width &lt= 480) #480 is the mobile width
console.log(\"Entered\");
$(\'#accounts-bar\').css(\"top\", bar_position)

return


I tried $(window).ready, $(window).load but all of them fail






Rating: 2 out of 5 based on 4 ratings



The post jquery – Running Javascript after CSS is fully loaded appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/jquery-running-javascript-after-css-is-fully-loaded.html

javascript – Onmouseover change the color of span: first-child color



I am getting problem here:



<ul id=\"parentnode\">
<li><span>I need color change here</span><span>no color</span><span>nocolor</span></li>
<!-- continuing li tags from database -->
</ul>


Here, Onmouseover <li> tag i have to change the color of text which is inside the <span> first-child.

Is it possible to change through Javascript, How ?


Note: It is not possible to give id\’s to <li> tag or <span> tag, because they are dynamically presenting from database.


Thank you.






Rating: 1 out of 5 based on 3 ratings



The post javascript – Onmouseover <li> change the color of span: first-child color appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-onmouseover-li-change-the-color-of-span-first-child-color.html

html – How to insert a javascript file into an iframe then call a function in the inserted javascript?



Edit: Just found out this is a chrome problem, the code works fine in firefox


I have an iframe on a webpage that shows a book formatted as html. I would like to insert some javascript within this iframe to make the book more dynamic (e.g. click on sentences, show animations etc). The iframe content is in the same domain as the parent page.


I can insert the javascript into the iframe but get an error calling a function in the inserted javascript. I\’ve described the different bits of code below:


My parent page javascript is:



function iframeLoaded()
{
var iFrameID = document.getElementById(\'preview-iframe\');

var jsLink = iFrameID.contentDocument.createElement(\"script\");
jsLink.src=\"/tests/iframeAPI.js\";
jsLink.type = \'text/javascript\';
iFrameID.contentDocument.head.appendChild(jsLink);
iFrameID.contentWindow.initialiseApi()
}


and the html containing the iframe is:



<iframe id=\"preview-iframe\" width=\"640\" height=\"240\" frameborder=\"0\" src=\"./testpage.htm\" onload=\"iframeLoaded()\" scrolling=\"no\"></iframe>


The contents of iframeAPI.js is:



window.initialiseApi = function() { alert(\"Hello world\") }


Looking at the iFrame\’s html in the browser shows that the iFrameAPI.js tag is inserted ok into the iframe head, but I don\’t get the alert popup when the page is loaded. The error appears on the following line:



iFrameID.contentWindow.initialiseApi()
Uncaught TypeError: Object [object Window] has no method \'initialiseApi\'


However I can run this line in the browser\’s javascript console and the alert popup works fine.


Any help would be much appreciated.


Thanks,


Brian




Edit: I\’ve just tried with an onload event to make sure the page is loaded and I still have the problem:


My parent page javascript is now :



function iframeLoaded()
{
var iFrameID = document.getElementById(\'preview-iframe\');

var jsLink = iFrameID.contentDocument.createElement(\"script\");
jsLink.src=\"/tests/iframeAPI.js\";
jsLink.type = \'text/javascript\';
iFrameID.contentDocument.head.appendChild(jsLink);
jsLink.onLoad= iFrameLoaded();
}

function iFrameLoaded()
{
alert(\"Iframe loaded\"); // Alert works ok
var iFrameID = document.getElementById(\'preview-iframe\');
iFrameID.contentWindow.initialiseApi(); // Same error message on this line
}






Rating: 4 out of 5 based on 3 ratings



The post html – How to insert a javascript file into an iframe then call a function in the inserted javascript? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/html-how-to-insert-a-javascript-file-into-an-iframe-then-call-a-function-in-the-inserted-javascript.html