|
In .net Project(Solution), Need to remove unused Javascript functions and variables from JS file.
In my project I'm having a lot of js file upto 40 files. I have to remove the unwanted code.
Need help to identify unused CSS (Cascading Style Sheet) lines.
Kindly share your ideas and expecting the solution asap.
|
|
|
|
|
|
I am having a dickens of a time getting a particular function to behave properly. This is client-side script. I find that I have to enclode the variable to be returned in parenthesis, or the function will not run at all. However, the calling routine chokes on the return and never gives the value passed back. WHY would I have to put parenthesis around the return variable (e.g., Return (VName);) in order for my function to run. WHAT am I doing wrong (I am new to JavaScript). Here is the code. I never get to the second alert.
function SetFund(){
alert('1');
var FundVal = GetFundValue();
alert('2');
}
function GetFundValue() {
var FundVal = '143';
var strRef = document.referrer;
if (strRef == '')
{
Return(FundVal);
}
else
{
strRef=strRef.replace('http://','');
strRef=strRef.replace('https://','');
var i =strRef.indexOf('/');
strRef=strRef.substr(i+1);
strRef=strRef.replace(new RegExp('/', 'g'),'');
strRef=strRef.replace(new RegExp('-', 'g'),'');
var FDID = GetDesigID();
var fdes = document.getElementById(FDID);
var strTmp=fdes.innerHTML.replace(new RegExp('<option value="', 'g'),'');
var strTmp=strTmp.replace(new RegExp('<option selected="selected" value="', 'g'),'');
var strTmp=strTmp.replace(new RegExp(' ', 'g'),'');
var strTmp=strTmp.replace(new RegExp(String.fromCharCode(9), 'g'),'');
var strTmp=strTmp.replace(new RegExp(String.fromCharCode(10), 'g'),'');
var strTmp=strTmp.replace(new RegExp('">', 'g'),',');
strTmp=strTmp.toLowerCase();
var strHTML = strTmp.split('</option>');
for(var i = 0; i < strHTML.length; i++)
{
var FundValuePair = strHTML[i].split(',');
if(FundValuePair[1].indexOf(strRef) > 0){
FundVal = FundValuePair[0];
Return(FundVal);
}
}
Return(FundVal);
}
}
|
|
|
|
|
Javascript is case-sensitive, and "return" should be in lower case.
By wrapping the value after "Return" in parentheses, you're turning it into a call to a function called "Return" that doesn't exist, which will throw an exception.
|
|
|
|
|
Graham:
Without the parentheses, the code does not even get entered. I put an "alert" at the very top of the function, and it never gets there. So I get it on not using parentheses on the Return statement. However, what else is wrong with the code that would make it non-functioning?
|
|
|
|
|
Without the parentheses, the code contains a syntax error - the parser will give up and not execute it.
With the parentheses, the parser will accept that you want to call a function called "Return" (assuming that it will be defined later) and only fail when you try to call it.
These errors are fairly easy to spot if you use your browser's development tools (or at least take a look at the Javascript console).
|
|
|
|
|
My problem is I have "Return" capitalized!! I do not have a smart javascript development environment. My editor catches no errors. I spent hours trying to figure out what was wrong. Argh!!
|
|
|
|
|
Which is exactly what Graham said[^] 6 hours ago.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Javascript is case-sensitive, and "return" should be in lower case.
"Return(FundVal)" should be written by "return FundVal"
|
|
|
|
|
I've got ten questions here. All questions have two possible answers but only one is correct and I would like to know how to make the answer appear underneath its question after the submit button is pressed. Also sorry if you find some of the questions offensive but that's the kind of demographic I'm trying to reach out to. Anyway here's the code:
<p class="question">1.Would you rather be 2 foot tall or 10 foot tall?</p>
<input id="q1a" type="radio" name="q1" value="a" /><label for="q1a"> 2 foot tall</label>
<input id="q1b" type="radio" name="q1" value="b" /><label for="q1b"> 10 foot tall</label>
<p class="question">2.Would you rather be blind or deaf?</p>
<input id="q2a" type="radio" name="q2" value="a" /><label for="q2a"> Blind</label>
<input id="q2b" type="radio" name="q2" value="b" /><label for="q2b"> Deaf</label>
<p class="question">3.Would you rather be poor and work at a job you love or be rich and work at a job you hate?</p>
<input id="q3a" type="radio" name="q3" value="a" /><label for="q3a"> Poor and love my job</label>
<input id="q3b" type="radio" name="q3" value="b" /><label for="q3b"> Rich and hate your job</label>
<p class="question">4.Would you rather be homeless and have family and friends or not be homeless and live without family?</p>
<input id="q4a" type="radio" name="q4" value="a" /><label for="q4a"> Homeless with family and friends</label>
<input id="q4b" type="radio" name="q4" value="b" /><label for="q4b"> Not homeless without family and friends</label>
<p class="question">5.Would you rather have no legs or no arms?</p>
<input id="q5a" type="radio" name="q5" value="a" /><label for="q5a"> No legs</label>
<input id="q5b" type="radio" name="q5" value="b" /><label for="q5b"> No arms</label>
<p class="question">6.Would you rather have a vagina on your forehead or a penis on your belly-button?</p>
<input id="q6a" type="radio" name="q6" value="a" /><label for="q6a"> Vagina on my forehead</label>
<input id="q6b" type="radio" name="q6" value="b" /><label for="q6b"> Penis on my belly-button</label>
<p class="question">7.Would you rather molest a penguin and nobody knows or not molest a penguin and everyone thinks that you have?</p>
<input id="q7a" type="radio" name="q7" value="a" /><label for="q7a"> Do it and nobody knows</label>
<input id="q7b" type="radio" name="q7" value="b" /><label for="q7b"> Everybody just thinks that you did</label>
<p class="question">8.Would you rather be absolutely freezing, naked, in Antarctica or wear a snowsuit in the desert?</p>
<input id="q8a" type="radio" name="q8" value="a" /><label for="q8a"> Naked in the Antarctica</label>
<input id="q8b" type="radio" name="q8" value="b" /><label for="q8b"> Snowsuit in the desert</label>
<p class="question">9.Would you rather count all the grains of sand on a beach or watch paint dry for 1 hour everyday for the next 10 years?.</p>
<input id="q9a" type="radio" name="q9" value="a" /><label for="q9a"> Count all grains of sand on a beach</label>
<input id="q9b" type="radio" name="q9" value="b" /><label for="q9b"> Watch paint dry everyday for the next 10 years</label>
<p class="question">10.Would you rather have all farts be silent but extremely deadly, it all farts be harmless but extremely loud?</p>
<input id="q10a" type="radio" name="q10" value="a" /><label for="q10a"> Silent but deadly</label>
<input id="q10b" type="radio" name="q10" value="b" /><label for="q10b"> Loud but harmless</label>
<div id="results">Get Answers!</div>
<div id="category1">
<strong>Question 1:</strong> The correct answer is 10 foot because being 10 foot is 5 times better than being 2 foot tall.
</div>
<div id="category2">
<strong>Question 2:</strong> The correct answer is deaf because if you can't see people could be doing anything to you.
</div>
<div id="category3">
<strong>Question 3:</strong> The correct answer is poor and love your job because it's better to be poor and happy than rich and happy. Well that's what I think anyway.
</div>
<div id="category4">
<strong>Question 4:</strong> The correct answer is homeless with family and friends because it's better to be poor and happy than sad and in a medium financial state.
</div>
<div id="category5">
<strong>Question 5:</strong> The correct answer is no legs because if you have no arms you can't do the dirty.
</div>
<div id="category6">
<strong>Question 6:</strong> The correct answer is a penis on your belly-button because you could have it amputated.
</div>
<div id="category7">
<strong>Question 7:</strong> The correct answer is do it and nobody knows. Why would you want people to think that you molested a penguin?
</div>
<div id="category8">
<strong>Question 8:</strong> The correct answer is snowsuit in the desert. You wouldn't want to catch hypothermia as it's worst than hyperthermia, plus that penguin might get you back while you're out there.
</div>
<div id="category9">
<strong>Question 9:</strong> The correct answer is watch paint dry everyday for 1 hour for the next 10 years because if you lose count of the sand half way through counting you'd have to start all over again.
</div>
<div id="category10">
<strong>Question 10:</strong> The correct answer is silent but deadly because you could just blame it on somebody else, nobody will know where it came from.
|
|
|
|
|
var TrueArray=new Array // numbers only of correct inputs
(
2, // 1 so fist input is correct, 2 so second input is correct
...
// false second input is correct
);
var TrueArrayLength=TrueArray.length;
insert function onkeypress or onmousewover ... what you want
<input id="q1a" type="radio" name="q1" value="a" onmouseover="javascript:GetTrueFalse(1,1);"/><label for="q1a"> 2 foot tall</label>
function GetTrueFalse(NumberOfQuestion,NumberOfCorrectfInput)
// NumberOfQuestion from 1 to TrueArrayLength
// NumberOfCorrectfInput value of field of array at index pos NumberOfQuestion-1
{
NumberOfQuestion--;
if((NumberOfQuestion>=0) && (NumberOfQuestion<TrueArrayLength)) // 0 to TrueArrayLength-1
{
if((NumberOfCorrectfInput>0) && (NumberOfCorrectfInput<3)) // 1 or 2
{
if(NumberOfCorrectfInput==TrueArray[NumberOfQuestion]) // got number of correct input ?
{
// correct e.g. alert("bingo!");
}
else
{
// not correct e.g. alert("nope");
}
}
}
}
have fun.
|
|
|
|
|
Hi,
This has both C# and Javascript. Not sure if it is the correct forum.
I have a hidden field value on an apsx page, which is populated on PageLoad. I am trying to request this value in javascript. The value does load from PageLoad, because I can see this value on page view source for the hidden aspx field. But when i try to request this value in javascript, the value is null. I know it is null since I am using alert statements to see this value. Am I missing a syntax? Many thanks!!
<script type="text/javascript">
ASPX code
<asp:HiddenField ID="hfEmail" runat="server" />
|
|
|
|
|
check emailAddress
emailAddress null pointer ?
property .value exists ?
range of value of .value ?
HTML
funktion document.getElementById() uses param during parsing of document
so '<%=hfEmail.ClientID%>' must be a real ID or filled BEFORE parsing javascript.
put javascript at end of body, no in head (head is parsed at first before body).
<script type="text/javascript">
.... what you want
//-->
</script></pre> // where is <pre>
</script>
|
|
|
|
|
Can you show the PageLoad function?
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).
|
|
|
|
|
This is the syntax, to be placed with in the body of email:
<asp:hiddenfield id="hdnCreateDate" runat="server">
var createdate = '<%=hdnCreateDate.Value%>';
|
|
|
|
|
try it in jquery ready function.
$(document).ready(function()
{
var hiddenVal=$("#YourId").val();
});
if you use master page in aspx, then you can find the element by name also.
$("input[name='elementName']")
|
|
|
|
|
is there a script to determine the optimal weight man?
|
|
|
|
|
How would you define the optimal weight in the first place? You would need a list that contains all the other parameters that woould lead you to the correct value.
Veni, vidi, abiit domum
|
|
|
|
|
whether he uses a loop if , switches .
|
|
|
|
|
You can use anything you like, but first you need to know what data you are feeding in, and what algorithm you will use to transform it to the required result.
Veni, vidi, abiit domum
|
|
|
|
|
Hello,
I've being trying to get some animations done in a canvas which are quite similar to Create an HTML5 (and JavaScript) Maze Game with a timer[^]. Unfortunately I've got the same erro that happens on the project's article. Unless you use Firefox you'll get:
Unable to get image data from canvas because the canvas has been tainted by cross-origin data.
Uncaught SecurityError: An attempt was made to break through the security policy of the user agent.
From my research, you can add to google chrome shortcut the extension --disable-web-security or host the files in a localhost server.
Both ways can make it work, but I would like to know if there is a way for cross-origin not to taint the canvas? Something like a property from the canvas that I could disable/enable or some other coding related solution..
There are no secrets to success. It is the result of preparation, hard work, and learning from failure. Colin Powell
|
|
|
|
|
I sure hope not - if there was, what's to stop malicious code from loading images from your local file-system?
Just use a localhost server. You can write one in c++ that compiles to a 25kb executable. Of course, you could download Apache or a different one of your choosing.
"Science adjusts its views based on what's observed. Faith is the denial of observation, so that belief can be preserved." - Tim Minchin
|
|
|
|
|
In need of desperate guidance
1. Is there any way to avoid activex in javascript for reading
Documents and constructing xmls?
2. Actual there is an problem with the client, he doesnt like the IE security settings like "Access data source across domains" under Miscellaneous and "Run ActiveX controls and plug-ins".
And It should support IE 7,8 and above.If possible that should work in cross browser also.
Currently in Javascript, we are using the below codes:
var xmlDoc = new ActiveXObject("MSXML2.DOMDocument"); -->for xml construction.
var stm = new ActiveXObject("ADODB.Stream"); --> for reading the doc and docx file from client temporary path.
What is needed:
1. We need to find an alternate in order to avoid using the ActiveXobject.
OR
2. We need to automate the Internet Security Settings in client machine.
Could some one help me in this please?
Thanks
Nanda
|
|
|
|
|
If above ie. 6 you should be able to parse XML documents directly from Javascript - see here for example[^]
Accessing a file from the local machine, though, is more of a problem unless the user selects the file. Could you supply the file vie a web service, for example?
MVVM # - I did it My Way
___________________________________________
Man, you're a god. - walterhevedeich 26/05/2011
.\\axxx
(That's an 'M')
|
|
|
|