We have a program which runs either on a live environment or on a test environment. The only difference is that the URL on the test environment contains "/test/". When in the test environment, some functions cause it to switch to the live environment (when the URL was hard coded!), so I'm trying to fix that.
I have created this function in JavaScript:
function GetTestMode()
{
// If "/test/" exists in URL, keep it there (we are in test mode).
var currentURL = document.URL;
var sTestMode = "";
if (currentURL.indexOf("/test/") != -1)
{
// test mode (according to URL)
sTestMode = "test/";
}
return sTestMode;
}
This is used by the JavaScript functions and works as expected.
However, most of the UI code is in Python (creating HTML). So I want to get this JavaScript result in Python. So far I have:
import cgi
import os
import sys
import re
def DrawUI (self, short=False):
print '<br />'
print '<div class="box2">'
print '<table cellspacing=0 cellpadding=0 border="0">'
print '<tr>'
sTestMode = "test mode = %s" % ('<a href="javascript:GetTestMode()" >')
print 'sTestMode = ' + sTestMode + '<br />'
This causes the print statements following this code (which can even be print 'hello world'
) to become a link which, if I click on it, displays the correct return value from the JavaScript function in the browser.
How can I get sTestMode
to contain the return value (without user interaction)?