I have a website, this website is running JavaScript scripts.
Now I have another python script that is running on another machine (in another network even) that should call a JS function on that specific website.
Now, how do I go about that?
I was thinking about a URL that directs to that very JS function...
But how do I call it then?
I tryed to search it, never really found anything like that... Only somewhat related, but never how to call it from a different machine in a different network.
Clarification:
I want to trigger the "Delete Comment" button in Steam Groups via python.
The URL is http://steamcommunity.com/groups/[name]#comments and the JS function call is
javascript:CCommentThread.DeleteComment( 'clanID', 'commentID' );
So I found this script:
http://steamcommunity-a.akamaihd.net/public/javascript/forums.js
Any idea how to trigger a function in there?
Related
I have two PHP files one called cab.php and another called d3.php , I want to toggle
in the same file this works cab.php
the problem is when I call the second file d3.php
function botaod2mostraesconde()
{
$(".wrapd2").toggle();
$(".datad2").toggle();
$(".uploadd2").toggle();
}
here
the input button :
<input type="button" value="D3" onclick="location.href = 'd3.php'">
I am looking for a way to toggle from different files. Thanks
You will need to run the JavaScript on the next page (d3.php). You can't execute client side script (JavaScript) on a php page that runs server side which hasn't yet been loaded in the client's browser.
This is based on an edict written in stone eons ago:
Thou shalt not execute client side code before server side code.
This would be akin to Luke attempting to destroy the Death Star before it's been created. Wait for the Death Star, you must. Then use The Force to destroy it.
Run d3.php first, then toggle elements on the page using JavaScript.
Attempting something a bit complicated and I hope it is possible, or someone might suggest a way to do it.
On site A I have a database with booking information.
On site B I want to show people when these bookings are taking place.
So on site A I create a php page which takes all of that data and puts it into JSON.
I then create a js script to run an ajax call to that php page, return the information and use javascript to create a table and build it wherever the script was called.
Kind of like twitter's widget.
Now what I want to do, is have a couple of lines of code pasted into site B, which calls the js script on site A, which runs the ajax command, then gets the data, creates the table I mentioned and puts it on site B.
Is that possible? Will the script make the ajax call on site A before passing it to site B? Or will it not be able to do the ajax call because it is put on site B first and I can't call to site A from site B?
It is possible but the way is a bit different from you suggested.
Firstly to answer your questions: When you include that "data fetcher" script from site A on site B, it will be executed on Site B. It will try to perform ajax call to site A and will fail because of same-origin policy.
The way to accomplish this is via JSONP.
You need to first create a php page, which produces some json data and calls a predefined javascript function like:
fetcher.php:
<?php
$data = fetchCustomerBookings($_GET['customerid']);
echo "renderBookings(".json_encode($data).")";
?>
Then you can include this script on Site B with an ordinary script tag like:
<script type="text/javascript" src="http://site-a.com/fetcher.php?customerid=XXX"></script>
There you need to have defined renderBookings javascript function already.
I need a simple way to call a URL to send a command to the system without processing or displaying whatever result is returned. If I use simple HTML calls then the frame the page with the button is on changes to the result returned by my lighting system and my page of buttons goes away. If I use ajax then I run into cross domain issues.
At it's simplest I would just like to have a button process an onclick() and execute a URL (e.g. http://www.mydomain.com/lightingdevice/on) in the background or some simple javascript that runs this same URL while the frame continues to display the page with the button.
Either way you need to use AJAX if you need to do this discretely.
The interface is on the same domain as your application: just use AJAX properly and you're good.
The interface is on some another domain as your application: create an interface on the same domain as your application, using PHP for example. This will let you use AJAX. Then just let PHP handle all the rest.
I am trying to write a Perl script that will take a user parameter from command line and with his parameter, Perl script will call a JavaScript function in a HTML page. How can I go ahead to with this?
Not that I've seen. Perl is strictly server side, and JS functions you're talking about are on the client.
The closest you would get is have the Perl script write a block into the HTML page so that the page fires it on load to perform the action. But that's a little shaky at best to do.
It depends on whether the browser or server will be taking the first step.
If the server needs to run code first and then execute some JS, then #skyburner's solution would work. Essentially you would already have some functions defined on the page, but then you would dynamically add a block of JS to call whichever function you need to.
However, if the Perl is being run due to a user's action on the current page (such as clicking something or submitting a form), then AJAX would be the way to go. You would use JS to submit an HTTP request to the Perl script. The Perl would then return some value back to the JavaScript and execute some function based on this result. This would all happen "behind-the-scenes" without the user leaving the page.
If I understand correctly about what you want, since not all the browsers support socket, this is what you can do:
Have an ajax service call periodically sending requests to the server for update
Once the the parameters from the command line are taken, you can send the result along with an ajax response back to the page, and call the function in the ajax request callback function.
Also, another option, you can use reverse ajax to accomplish this. See Wikipedia about reverse ajax (comet), especially Ajax with long polling.
Problem
I am not able to refresh the page with window.location.reload() which is used inside the success call made to yahoo.
Any hints how it can be fixed.
The whole of the code is working fine it is making call to cse server getting contents from there saving on yahoo. but i have to manually refresh the page to bring the contents. I want it to be automatic so I used window.location.reload() but thats not working. Any suggestions how it can be done. The function below is actually a function for a button.
That's the problem, right there.
If your script is running from the CSE server's domain, you cannot send data to the yahoo server. This is javascript's main limitations. Likewise, if running off of the yahoo domain, you can send data to it, but cannot send data to the CSE server, unless it is part of the yahoo domain.
Would work:
Get data from blahblahblah.yahoo.com, then send data to somedomain.yahoo.com
Would not work:
Get data from blahblahblah.somesite.com and send data to somedomain.yahoo.com
Main point, if you're getting data from "csce.unl.edu" and running off of that domain (aka running your script in a browser window from that domain), you can only send data to a site that ends with ".unl.edu". So you can send or receive from "test.unl.edu", but not some yahoo site.
A solution:
Host a proxy script on some webserver, or write all of your code in PHP. Here is two great references on what a proxy script is, and the second link actually provides one for you:
Link 1
Link 2
Any more help needed, you can let me know, I had to set one up myself, on my server, and I can help you out if you run into problems.
did you tried:
window.location = window.location;