Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

There is Javascript code on the interface's HTML page which I reckon is making the webpage interactive and defining the behaviour of the page. Firstly, can I send Javascript commands from Python to switch the sockets using the web interface (if I have TCP/IP connection to the server opened from Python.) So, for that I would need to call a Javascript function in a Python shell. How to do that? Secondly, do I need cometcomet in this case, because I need to push Javascript command to a particular IP and port from Python.

There is Javascript code on the interface's HTML page which I reckon is making the webpage interactive and defining the behaviour of the page. Firstly, can I send Javascript commands from Python to switch the sockets using the web interface (if I have TCP/IP connection to the server opened from Python.) So, for that I would need to call a Javascript function in a Python shell. How to do that? Secondly, do I need comet in this case, because I need to push Javascript command to a particular IP and port from Python.

There is Javascript code on the interface's HTML page which I reckon is making the webpage interactive and defining the behaviour of the page. Firstly, can I send Javascript commands from Python to switch the sockets using the web interface (if I have TCP/IP connection to the server opened from Python.) So, for that I would need to call a Javascript function in a Python shell. How to do that? Secondly, do I need comet in this case, because I need to push Javascript command to a particular IP and port from Python.

clarifying the language so the question is a little more clear
Source Link

I have a device precisely, a board of four programmable electric sockets (four to be exact). The device's interface with the pc is through tcpthe TCP/ipIP port. The device has itsa web browser user interface based on default ip, accessible at a local IP address.

There is javascriptJavascript code behindon the htmlinterface's HTML page of the interface which I reckon is making the webpage interactive and defining the behaviour of the page. Firstly, can I send javascriptJavascript commands from python shellPython to switch the sockets using the web interface ( ifif I have tcp ipTCP/IP connection betweento the server and client in python codeopened from Python.) So, for that I would need to call javascripta Javascript function in pythona Python shell. How to do that? secondlySecondly, do I need comet in this case, because I need to push javascriptJavascript command to a particular ipIP and port from pythonPython.

I have a device precisely a board of programmable electric sockets (four to be exact). The device's interface with pc is through tcp/ip port. The device has its web browser user interface based on default ip.

There is javascript code behind the html page of the interface which I reckon is making the webpage interactive and defining the behaviour of the page. Firstly, can I send javascript commands from python shell to switch the sockets ( if I have tcp ip connection between server and client in python code.) So, for that I need to call javascript function in python shell. How to do that? secondly, do I need comet in this case because I need to push javascript command to a particular ip and port from python.

I have a device, a board of four programmable electric sockets to be exact. The device's interface with the pc is through the TCP/IP port. The device has a web browser user interface, accessible at a local IP address.

There is Javascript code on the interface's HTML page which I reckon is making the webpage interactive and defining the behaviour of the page. Firstly, can I send Javascript commands from Python to switch the sockets using the web interface (if I have TCP/IP connection to the server opened from Python.) So, for that I would need to call a Javascript function in a Python shell. How to do that? Secondly, do I need comet in this case, because I need to push Javascript command to a particular IP and port from Python.

Cleaned up formatting of JavaScript sample (clang-format)
Source Link

and this is the javascript function: function ChangeState(sn){f = document.forms.tForm;ind = sn * 1 - 1;f["cte" + sn].value = Math.abs(1 - sockstates[ind]);f.submit();}function

ActivateDeactivate(){f = document.forms.tForm2;f["activate"].value = actbtn;f.submit();}function TimerFunction(){clearTimeout(timer);if

(trycon==1&&active==1){document.location.href = "xyz.html";}}function StartTimer(){timer = setTimeout(TimerFunction, period);}window.onload =

function (){for(i = 0; i<4; i++){if(sockstates[i]==0){clsname = 'offstate';str1 = 'OFF';str2 = 'ON';}else{clsname = 'onstate';str1 = 'ON';str2 =

'OFF';}strhtml = '' + str1 + ' '

  • str2 + '';el = document.getElementById('stCont' + i);el.innerHTML = strhtml;}statA = '';statB = '';statC = '';rmsg = '';if(ipid!=0){statA =

"Registered - ";tmpel = document.getElementById('regBtn');tmpel.innerHTML = 'Login';}else{rmsg = "Register to manage AB-xyz-LAN from Internet (

free service )";}if(active==1){statB = "Activated - ";}else{statB = "Not activated";}if(active==1){if(trycon==1){statC = "Trying to connect";}

else if(serv==1){statC = "Connected";}else if(serv==0){statC = "Not connected";}}statAel = document.getElementById('statusA');statAel.innerHTML =

statA;statBel = document.getElementById('statusB');statBel.innerHTML = statB;statCel = document.getElementById('statusC');statCel.innerHTML =

statC;rmsgel = document.getElementById('regmsg');rmsgel.innerHTML = rmsg;actBtnEl = document.getElementById("actBtn");if(actbtn==1)

{actBtnEl.innerHTML = 'Activate';}else{actBtnEl.innerHTML = 'Deactivate';}regBtnEl = document.getElementById("regBtn");regBtnEl.href =

"http://www.example.com/user/register.aspx?mac=" + mac;if (warn==1) {alert("Failed to connect. Please, check DNS server settings.");}if (warn==2)

{alert("Failed to activate. Please, check, that device is registered.");}StartTimer();}

function ChangeState(sn) {
 f = document.forms.tForm;
 ind = sn * 1 - 1;
 f["cte" + sn].value = Math.abs(1 - sockstates[ind]);
 f.submit();
}
function ActivateDeactivate() {
 f = document.forms.tForm2;
 f["activate"].value = actbtn;
 f.submit();
}
function TimerFunction() {
 clearTimeout(timer);
 if (trycon == 1 && active == 1) {
 document.location.href = "xyz.html";
 }
}
function StartTimer() { timer = setTimeout(TimerFunction, period); }
window.onload = function() {
 for (i = 0; i < 4; i++) {
 if (sockstates[i] == 0) {
 clsname = 'offstate';
 str1 = 'OFF';
 str2 = 'ON';
 } else {
 clsname = 'onstate';
 str1 = 'ON';
 str2 = 'OFF';
 }
 strhtml = '<span class="' + clsname + '">' + str1 +
 '</span>&nbsp;<a href="javascript: ChangeState(\'' + (i + 1) +
 '\')" class="onoffbtn">' + str2 + '</a>';
 el = document.getElementById('stCont' + i);
 el.innerHTML = strhtml;
 }
 statA = '';
 statB = '';
 statC = '';
 rmsg = '';
 if (ipid != 0) {
 statA = "Registered - ";
 tmpel = document.getElementById('regBtn');
 tmpel.innerHTML = 'Login';
 } else {
 rmsg = "Register to manage AB-xyz-LAN from Internet ( free service )";
 }
 if (active == 1) {
 statB = "Activated - ";
 } else {
 statB = "Not activated";
 }
 if (active == 1) {
 if (trycon == 1) {
 statC = "Trying to connect";
 } else if (serv == 1) {
 statC = "Connected";
 } else if (serv == 0) {
 statC = "Not connected";
 }
 }
 statAel = document.getElementById('statusA');
 statAel.innerHTML = statA;
 statBel = document.getElementById('statusB');
 statBel.innerHTML = statB;
 statCel = document.getElementById('statusC');
 statCel.innerHTML = statC;
 rmsgel = document.getElementById('regmsg');
 rmsgel.innerHTML = rmsg;
 actBtnEl = document.getElementById("actBtn");
 if (actbtn == 1) {
 actBtnEl.innerHTML = 'Activate';
 } else {
 actBtnEl.innerHTML = 'Deactivate';
 }
 regBtnEl = document.getElementById("regBtn");
 regBtnEl.href = "http://www.example.com/user/register.aspx?mac=" + mac;
 if (warn == 1) {
 alert("Failed to connect. Please, check DNS server settings.");
 }
 if (warn == 2) {
 alert("Failed to activate. Please, check, that device is registered.");
 }
 StartTimer();
}

and this is the javascript function: function ChangeState(sn){f = document.forms.tForm;ind = sn * 1 - 1;f["cte" + sn].value = Math.abs(1 - sockstates[ind]);f.submit();}function

ActivateDeactivate(){f = document.forms.tForm2;f["activate"].value = actbtn;f.submit();}function TimerFunction(){clearTimeout(timer);if

(trycon==1&&active==1){document.location.href = "xyz.html";}}function StartTimer(){timer = setTimeout(TimerFunction, period);}window.onload =

function (){for(i = 0; i<4; i++){if(sockstates[i]==0){clsname = 'offstate';str1 = 'OFF';str2 = 'ON';}else{clsname = 'onstate';str1 = 'ON';str2 =

'OFF';}strhtml = '' + str1 + ' '

  • str2 + '';el = document.getElementById('stCont' + i);el.innerHTML = strhtml;}statA = '';statB = '';statC = '';rmsg = '';if(ipid!=0){statA =

"Registered - ";tmpel = document.getElementById('regBtn');tmpel.innerHTML = 'Login';}else{rmsg = "Register to manage AB-xyz-LAN from Internet (

free service )";}if(active==1){statB = "Activated - ";}else{statB = "Not activated";}if(active==1){if(trycon==1){statC = "Trying to connect";}

else if(serv==1){statC = "Connected";}else if(serv==0){statC = "Not connected";}}statAel = document.getElementById('statusA');statAel.innerHTML =

statA;statBel = document.getElementById('statusB');statBel.innerHTML = statB;statCel = document.getElementById('statusC');statCel.innerHTML =

statC;rmsgel = document.getElementById('regmsg');rmsgel.innerHTML = rmsg;actBtnEl = document.getElementById("actBtn");if(actbtn==1)

{actBtnEl.innerHTML = 'Activate';}else{actBtnEl.innerHTML = 'Deactivate';}regBtnEl = document.getElementById("regBtn");regBtnEl.href =

"http://www.example.com/user/register.aspx?mac=" + mac;if (warn==1) {alert("Failed to connect. Please, check DNS server settings.");}if (warn==2)

{alert("Failed to activate. Please, check, that device is registered.");}StartTimer();}

and this is the javascript function:

function ChangeState(sn) {
 f = document.forms.tForm;
 ind = sn * 1 - 1;
 f["cte" + sn].value = Math.abs(1 - sockstates[ind]);
 f.submit();
}
function ActivateDeactivate() {
 f = document.forms.tForm2;
 f["activate"].value = actbtn;
 f.submit();
}
function TimerFunction() {
 clearTimeout(timer);
 if (trycon == 1 && active == 1) {
 document.location.href = "xyz.html";
 }
}
function StartTimer() { timer = setTimeout(TimerFunction, period); }
window.onload = function() {
 for (i = 0; i < 4; i++) {
 if (sockstates[i] == 0) {
 clsname = 'offstate';
 str1 = 'OFF';
 str2 = 'ON';
 } else {
 clsname = 'onstate';
 str1 = 'ON';
 str2 = 'OFF';
 }
 strhtml = '<span class="' + clsname + '">' + str1 +
 '</span>&nbsp;<a href="javascript: ChangeState(\'' + (i + 1) +
 '\')" class="onoffbtn">' + str2 + '</a>';
 el = document.getElementById('stCont' + i);
 el.innerHTML = strhtml;
 }
 statA = '';
 statB = '';
 statC = '';
 rmsg = '';
 if (ipid != 0) {
 statA = "Registered - ";
 tmpel = document.getElementById('regBtn');
 tmpel.innerHTML = 'Login';
 } else {
 rmsg = "Register to manage AB-xyz-LAN from Internet ( free service )";
 }
 if (active == 1) {
 statB = "Activated - ";
 } else {
 statB = "Not activated";
 }
 if (active == 1) {
 if (trycon == 1) {
 statC = "Trying to connect";
 } else if (serv == 1) {
 statC = "Connected";
 } else if (serv == 0) {
 statC = "Not connected";
 }
 }
 statAel = document.getElementById('statusA');
 statAel.innerHTML = statA;
 statBel = document.getElementById('statusB');
 statBel.innerHTML = statB;
 statCel = document.getElementById('statusC');
 statCel.innerHTML = statC;
 rmsgel = document.getElementById('regmsg');
 rmsgel.innerHTML = rmsg;
 actBtnEl = document.getElementById("actBtn");
 if (actbtn == 1) {
 actBtnEl.innerHTML = 'Activate';
 } else {
 actBtnEl.innerHTML = 'Deactivate';
 }
 regBtnEl = document.getElementById("regBtn");
 regBtnEl.href = "http://www.example.com/user/register.aspx?mac=" + mac;
 if (warn == 1) {
 alert("Failed to connect. Please, check DNS server settings.");
 }
 if (warn == 2) {
 alert("Failed to activate. Please, check, that device is registered.");
 }
 StartTimer();
}
added 60 characters in body
Source Link
Loading
deleted 6 characters in body
Source Link
Loading
added 1966 characters in body
Source Link
Loading
edited body
Source Link
Loading
added OP's python code from a comment.
Source Link
Timothy Groote
  • 8.7k
  • 29
  • 53
Loading
Source Link
Loading
default

AltStyle によって変換されたページ (->オリジナル) /