Following is what I want to accomplish:
In the html When the page loads(onload) I want to run a CGI script which is a C program to run a function in it.
I am thinking of calling a JS function onload in html:
<body onload="MyJsFunc();">
then in the JS file:
function MyJsFunc()
{
//call MyCGIfunc()
}
Now, how do I call my cgi above?
I am not sure if what I am trying to accomplish is doable or not.
Note: I cant use jquery
CGI programs are executed by making an HTTP request to them.
If you want to trigger them when a page is loaded, then the usual approach is to have the page be generated from the CGI program in the first place.
Failing that, you can use a Server Side Include to call the CGI program. (Note: You need to have your server configured to parse your HTML document for SSI directives).
<!--#exec cmd="./my_cgi" -->
If you really want to use JavaScript, then you will have to make the browser issue an additional HTTP request. This is usually done using the XMLHttpRequest object.
var myRequest = new XMLHttpRequest();
myRequest.open("GET", "/cgi-bin/my_cgi");
myReqest.send();
you can use iframe to exec cgi. as :
<iframe src="/cgi-bin/script.cgi" width="300" height="150">
Related
I have got a JavaScript file (extremely obfuscated) on my site that handles videos.
And this JavaScript file requests another JavaScript file and that JavaScript file calls another and so on....
Can I wrap the first JavaScript file (maybe sandbox it) so any request for external resource will be redirect through my proxy?
I mean if the JavaScript file call:
http://example.com/another.js
After I will intercept the call it will be:
http://myproxy.com/?url=http://example.com/another.js.
It depends on how the js file calls the next one, By using an xhr request or by adding a script tag to the dom ... ?
I've made an script for processing XML:
Extracts parts of the XML-data and displays them on a HTML-/CSS-page.
Currently I use the stringified content of some arbitrary file for doing my development. Written as a string-literal into my JavaScript.
Works great. But now comes the problem:
Of course I would like to load whatever (equal-structured) XML-files. Instead of having it in my code as a string-literal.
Normally I would load the files into my script via Ajax.
But I can't install a web-server on these computer.
I'm within an enterprise and it isn't possible to install any additional software. Restricted via group-policies etc. No chance. Forget it!
As far as I know it isn't possible to use Ajax without a web-server because Ajax communicates via the http-protocol.
So here's my questions:
I there (perhaps) a possibility to use Ajax without a web-server?
And in case of impossible:
Have I got any Ajax-alternatives to load XML-data into my script?
You can embed your xml inside script tag in your html like this:
console.log(document.getElementById('file').innerHTML)
<script type="text/xml" id="file">
<root><foo><bar></bar></foo></root>
</script>
I'm truing to execute a yui js script with js.executeScript Selenium's method.
The script is being executed by selenium webdriver in order simulate a "click" on hybrid mobile app (the button is webview)
String IncludeYUI = "script = document.createElement('script');script.type = 'text/javascript';script.async = true;script.onload = function(){};script.src = '"
+ YUI_PATH
+ "';document.getElementsByTagName('head')[0].appendChild(script);";
js.executeScript(IncludeYUI);
where the YUI_PATH is an url - https://cdnjs.cloudflare.com/ajax/libs/yui/3.18.0/yui/.....
The problem is that I do not have an access to the global network from the current site.
so I was thinking to save the script under the project and just to load it from FS.
But this is a js , no access to the FS ...
Any ideas how to load the script ?
Thanks
So, you're loading an html page somewhere, right? Conceptually you would load your JS file the same way: you make a request to your server to load the JS file, just like you did to load your html page.
That would look like this:
<script src="scripts/yourFile.js">
Also, I've never seen anyone loading a js file like you're doing in your code sample...I would most definitely just recommend putting a script tag in your html.
You may want to post your html code as well; we'll be able to provide better help. I'll update this answer accordingly if needed.
Finally , after many tries , some1 has suggested me to work with jquery.
after some digging , I've used executeScript with jquery's tap , and it worked...
$('#btn_login_button').trigger('tap');
I was wondering all other methods with click and element's coordinates didn't work
I'm using Netbeans 7.3.1, and usually I can successfully debug PHP files using Xdebug. However, that's only if my site project is structured in such a way that the site is generated from PHP code right off the bat.
Right now I have a site which is mostly made from HTML files. The HTML static, not generated by PHP. The only PHP file in the project is called phphandler.php. I need to debug that PHP file, but it only runs in response to a Javascript/jQuery call from within the HTML files that looks like this:
$.post(siteURL + 'jsonhandler.php', {
JSON: JSON.stringify(data)
}, processResult, "json");
On the PHP side, it processes the JSON request from $_POST
$Array = json_decode(stripslashes($_POST['JSON']), true);
When I run the debugger from within JSON, it opens Chrome and loads my site, starting with index.html, but the debugger never opens jsonhandler.php. I can go through all the links and navigate through my site, and it will get all the JSON data it needs from jsonhandler.php, but the debugger remains uninvolved.
Can I debug through jsonhandler.php when the Javascript sends it a request via $_POST, and if so, how?
Update: I've discovered that I can debug jsonhandler.php using the Debug File function, but this has serious drawbacks, namely that I can't create a situation in which jsonhandler.php is receiving JSON data as constructed by the rest of the site. I can manually force in some hand made test JSON data, but then that seriously inhibits my ability to discover what the system is doing as a whole.
Anyway, for me this is another indicator that the debugging environment is configured correctly, it's just a matter of if and how the debugger can listen for the right events.
What I normally do is putting break points. Try putting breakpoints to the PHP code that receives the request (or that you want to debug) in the jsonhanler.php file and them run in debug mode, navigate through your site and send the request, the debugger should open Netbeans and take you to the line where you left the breakpoint. From there you can now go line by line or jump into functions.
You can try printing the $Array received in the php file by print_r($Array) followed by an exit() which might stop the process in the php file and show you the result coming in the php file. This might allow you to see as to what the php file is getting when it is loaded in the $Array. Or else if its an ajax request you can print the response in the console by console.log(response). I hope it helps.
I recently responded to a similar question here: https://stackoverflow.com/a/19636910/212076
Basically, you need to add a query parameter within your JSON to trigger the debugger:
XDEBUG_SESSION_START=netbeans-xdebug
If the data is being obtained directly from a HTML Form, then include a hidden field like so:
<input type="hidden" name="XDEBUG_SESSION_START" value="netbeans-xdebug" />
This sounds like a trivia question but I really need to know.
If you put the URL of an HTML file in the Location bar of your browser, it will render that HTML. That's the whole purpose of a browser.
If you give it a JPG, or a SWF, or even PDF, it will do the right things for those datatypes.
But, if you give it the URL of a JavaScript file, it will display the text of that file. What I want is for that file to be executed directly.
Now, I know that if you use the javascript: protocol, it will execute the text of the URL, but that isn't what I need.
I could have the URL point to an HTML file consisting of a single <script> tag that in turn points to the JavaScript file, but for occult reasons of my own, I cannot do that.
If the file at http://example.com/file.js consists entirely of
alert("it ran");
And I put that URL in the Location bar, I want "it ran" to pop up as an alert.
I'm skeptical that this is possible but I'm hoping-against-hope that there is a header or a MIME type or something like that that I can set and miraculously make this happen.
This is not possible. The browser has no idea what context the JavaScript should run in; for example, what are the properties of window? If you assume it can come up with some random defaults, what about the behavior of document? If someone does document.body.innerHTML = "foo" what should happen?
JavaScript, unlike images or HTML pages, is dependent on a context in which it runs. That context could be a HTML page, or it could be a Node server environment, or it could even be Windows Scripting Host. But if you just navigate to a URL, the browser has no idea what context it should run the script in.
As a workaround, perhaps use about:blank as a host page. Then you can insert the script into the document, giving it the appropriate execution context, by pasting the following in your URL bar:
javascript:(function () { var el = document.createElement("script"); el.src = "PUT_URL_HERE"; document.body.appendChild(el); })();
Or you can use RunJS: https://github.com/Dharmoslap/RunJS
Then you will be able to run .js files just with drag&drop.
Not directly, but you could make a simple server-side script, e.g. in PHP. Instead of
http://example.com/file.js
, navigate to:
http://localhost/execute_script.php?url=http://example.com/file.js
Of course, you could smallen this by using RewriteRule in Apache, and/or adding another entry in your hosts file that redirects to 127.0.0.1.
Note that this is not great in terms of security, but if you use it yourself and know what you're downloading, you should be fine.
<html>
<head>
<script>
<? echo file_get_contents($_GET['url']); ?>
</script>
</head>
<body>
</body>
</html>
In the address bar, you simply write
javascript:/some javascript code here/;void(0);
http://www.javascriptkata.com/2007/05/01/execute-javascript-code-directly-in-your-browser/
Use Node.js.
Download and install node.js and create a http/s server and write down what you want to display in browser.
use localhost::portNumber on server as url to run your file.
refer to node js doc - https://nodejs.org/dist/latest-v7.x/docs/api/http.html
Run - http://localhost:3000
sample code below :
var http = require("http");
var server = http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/html'});
res.end("hello user");
}); server.listen(3000);`
you can write your own browser using qt /webkit and do that.
when user enters a js file in url location you can read that file and execute the javascript .
http://code.google.com/apis/v8/get_started.html is another channel.
not sure if it meets ur need.