vash
April 3, 2012, 5:32pm
1
With Internet Explorer 9 on Widows, I can’t access to python method from Javascript whereas the access to python attribute works well.
What I tried :
In my python file:
self.name = "x"
base.appRunner.main.resize = self.resize
base.appRunner.main.name= self.name
def resize(self):
print "bla"
In my javascript file:
var plugin = document.getElementById("myPlugin");
alert("name : "+plugin.main.name);
alert("method : "+plugin.main.resize());
The results are :
name : x
method : undefined
Does someone has an idea ?
PS : With the same syntax, It works well on many browsers like Firefox, Chrome.
rdb
April 3, 2012, 5:35pm
2
Your method doesn’t return anything, so I would expect the result to be “undefined”. Does it work if you return something else, such as 2 or so?
vash
April 4, 2012, 6:23am
3
No it doesn’t work even if my method returns something, the result is the same…
drwr
April 24, 2012, 6:29pm
4
Can you post a complete (but simple) example demonstrating the problem?
Thanks!
David
vash
April 25, 2012, 8:19am
5
Here, the code of my python class :
class World(DirectObject):
def __init__(self):
self.name = x
base.appRunner.main.name = self.name
base.appRunner.main.myTest = self.myTest
smiley = base.appRunner.dom.document.getElementById('smiley')
print "smiley ",smiley
def myTest(self):
print "myTest"
return 2
Now, my php page where I declare the object plugin
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Panda3d</title>
<script type="text/javascript" src="js/RunPanda3D.js"></script>
</head>
<body>
<script>
P3D_RunContent('data', 'http://127.0.0.1/packages/asteroids.0.1.p3d', 'id', 'scripty',
'width', '300', 'height', '300',
'auto_start', '1')
</script>
<div id="smiley">^_^</div>
<input type="button" value="fire" onclick="fire3()" />
<script type="text/javascript">
function fire3() {
var plugin = document.getElementById('scripty');
if (plugin.main!=null)
{
res = plugin.main.myTest();
alert("Result : "+res);
alert("Name : "+plugin.main.name);
}
}
</script>
</body>
</html>
With IE9, the results are :
Result : undefined
Name : xIn the p3dSession.log :
smiley [object HTMLDivElement]
The link from python to Javascipt works but not from Javascript to python
With another browser like Firefox, the results are :
Result : 2
Name : xIn the p3dSession.log :
smiley [object HTMLDivElement]
myTest