I have 2 files, one named client.php and one named habbo3.js. Inside the client.php there is something called "connection.info.host": that usually needs to have an IP.
However I'm trying to use it as a variable and get the IP from the JavaScript file. I tried doing it like down below but I'm getting an error on chrome developer tool
client:21 Uncaught ReferenceError: price1 is not defined(anonymous function) # client:21
My client.php file: http://pasted.co/0a5a803e
My habbo3.js file:
var price1 = 123.456.789;
var price2 = 222.222.222;
The numbers above are just false numbers but should be replaced with my VPS IP address. Any solution for this guys?
You're trying to load habbo3.js with this line:
<link src="http://.../habbo3.js">
You should replace it with:
<script type="text/javascript" src="http://.../habbo3.js"></script>
Related
I am trying to create a simple recipe-app with javascript.
I have 3 HTML files: index.html, create.html, edit.html
and 2 JS files.
I have a couple of DOM elements. One on index.html, Two on edit, Two on create.
Now when I open index.html I get an error:
recipe.js:14 Uncaught TypeError: Cannot set property 'value' of null
The problem here is that the code that the error is it's about edit.html not index.html.
Same problem on edit.html
Uncaught TypeError: Cannot read property 'appendChild' of null
at recipe.js:55
recipe.js code 55 is about index.html, not edit.html.
Is there a way to target an HTML file when using DOM.
document.getElementById("edit-body").value = getRecipeBody();
I want the code above to be only for edit.html, not for index.html or create.html.
edit-body is a form that is only on edit.html, not on index or create.html
document.getElementById('recipes').appendChild(recipeEl)
I want this code to be for index.html not for other HTML files because there is no #recipes ID on those files. The #recipes is only on index.html
I am using localStorage.
window.location.pathname would let you execute code for a specific path.
if(window.location.pathname === '/edit.html') {
document.getElementById("edit-body").value = getRecipeBody();
}
Note that if you load index.html by default (as in, http://localhost:80/ as opposed to http://localhost:80/index.html), then the pathname will simply be /, so make sure you handle both of those, i.e.:
if(window.location.pathname === '/index.html' || window.location.pathname === '/') {
document.getElementById('recipes').appendChild(recipeEl)
}
A better approach would be to code it defensively. Check that the element you're getting exists before running a function against it. For example:
var editEl = document.getElementById("edit-body");
if (editEl) {
editEl.value = getRecipeBody();
}
Instead of either of these, you could also just load index.js on index.html, edit.js on edit.html, etc., though you'd want to split out any shared functions into a separate (common) JS file.
I try to use a JSON object (all the object not just a piece) from Node through Jade inside my local myScript.js script.
And my Jade file:
span(class="glyphicon glyphicon-pencil" onclick="confirm(\"#{myJSON.taskid}\", \"update\", !{myJSON})")
But I have this:
Uncaught ReferenceError: myJSON is not defined.
Then I quit !{myJSON} as parameter in the call of function confirm() in onclick(), and I try with a script block:
script(type= "text/javascript" src="myScript.js").
var local_json =!{JSON.stringify(myJSON)};
In myScript.js I issued console.log(local_json), but I end up with the following error in the console:
Uncaught ReferenceError: local_json is not defined.
How I can do it?
You have to first create variable , then import your script file. so basically var local_json = !{JSON.stringify(myJSON)}
then import other script - script ( type = "text/javascript" src="myScript.js")
I've set up acceptance tests with codeception and phantomjs.
My website contains script elements:
<script src="/bla/test.js" type="text/javascript"></script>
The JavaScript file looks like this:
Bla = {
request: function(var) {
}
};
It looks like the content cannot be found since one of the buttons contains
onclick="return Bla.request('100')"
Running the acceptance test which clicks on this button shows me:
[Selenium browser Logs]
17:10:24.876 WARNING - SyntaxError: Parse error
17:10:25.121 WARNING - ReferenceError: Can't find variable: Bla
onclick (http://localhost/bla)
Screenshot and page source were saved into '/var/www/bla/_output/' dir FAIL
Does the first parse error already mean that the files have been loaded but contain errors? If so, how can I see the exact parse errors?
Requesting the JS file manually in the acceptance test works and it is the correct file (as the output shows):
$I->amOnPage('/bla/test.js');
I run codeception with the option --debug and looked at the output files where everything looked correct. How can I see if the JavaScript file has been imported correctly and if the parse error means that it failed, how do I get more information about the error?
edit:
Even if the parse error is not present I cannot access variables from a different JavaScript file.
When I have multiple script elements:
<script src="/bla/test0.js" type="text/javascript"></script>
<script src="/bla/test1.js" type="text/javascript"></script>
I get an error:
ReferenceError: Can't find variable: Bla
in file test1.js if it was defined in test0.js. This works in the normal browser without errors.
Just a simple .js file in one of my drive which contains code
var x=3;
function numSqaure(x)
{
return(x*x);
}
var sentence="The square of" + x + "is" + numSqaure(x);
console.log(sentence);
I'm trying to run it through Powershell but it shows an error 'console' is undefined .
How to handle this error? I want it through Powershell only.
Javascript files are made for being executed by a browser, not directly in console unless you're using Node.js or something similar.
Create an HTML with a script tag like this:
<script src="c:\whatever\folder\you\choose\yourscript.js"></script>
and enter developer tools in browser. There this error won't happen anymore and console will exist.
I'm trying to execute a java program from within an HTML file using Javascript (specifically, the assignment is to activate an FTP server from an HTML interface, so I need to execute the FTPServer class from a function on my HTML page). I've been trying to use the following code to execute the "program" class which should simply print out "hello." The Chrome console says "Uncaught ReferenceError: java is not defined"
var p1 = java.lang.Runtime.getRuntime().exec("javac program.java");
document.getElementById("test").innerHTML = "working";
var p2 = java.lang.Runtime.getRuntime().exec("cmd /c java program");
var stdInput = new java.io.BufferedReader(new java.io.InputStreamReader(p2.getInputStream()));
var stdError = new java.io.BufferedReader(new java.io.InputStreamReader(p2.getErrorStream()));
I've also tried doing Packages.java.lang.Runtime... to which I get the error "Packages is not defined." I've tried importing the java.lang package:
importPackage(java.lang);
but I get the same error, "Uncaught ReferenceError: importPackage is not defined"
Why isn't importPackage working, and how can I get Runtime to work?
What you are trying to do only makes sense in rhino.
According to Rhino Migration Guide you can try something like this:
var Runtime = Java.type("java.lang.Runtime");
and then run it with
Runtime.getRuntime().exec("javac program.java");