How to pass Paper.set() to another Javascript in my case?
I have a index.html page, which contains a buttonid="my-btn"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My INDEX PAGE</title>
</head>
<body>
<div id="my-canvas"></div>
<br><input type="button" id="my-btn" value="OPEN NEW WINDOW"/>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/raphael.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/my.js"></script>
</body>
</html>
js/my.js invoke createCircle
function from my-graph.js, and handles button click event, when my-btn
button is clicked, a new browser window will be popped up with a new page (test.html)
my.js:
MyTest.createCircle();
$('#my-btn').click(function(){
window.open('test.html', 'testwindow');
});
my-graph.js:
MyTest= function(){
var paper = Raphael("my-canvas", 320, 200);
var st=paper.set();
return {
createCircle: function(){
st.push(
paper.circle(10, 10, 5),
paper.circle(30, 10, 5)
)开发者_如何学Python;
}
getSet: function(){
return st;
}
};
}();
The new page(test.html) opened in new browser window:
test.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TEST</title>
</head>
<body>
<div id="my-name"></div>
<script src="js/jquery-1.5.1.js"></script>
<script src="js/my-graph.js"></script>
<script src="js/test.js"></script>
</body>
</html>
In the new page, test.js will be invoked and I want to pass the Paper.set() st
from my-graph.js to this test.js and output st.length
as the content of this page
js/test.js
$(document).ready(function(){
var st=MyTest.getSet();
$("#my-name").append("<strong>"+st.length+"</strong>");
});
But I always get 0 length of the st in new popped up page. Why?
so your opening a new page with script references to the same code as the other page
That dosent mean that they have the same state. The new page will get its own state from evaluating the script itself
what you can do is save the reference that
var w = window.open('test.html', 'testwindow');
returns you can use that for calling a function on your new page
or you can yost do all the code on the start page with jquery and useing that window object as your context
var w = window.open('test.html', 'testwindow');
$(w).ready(function() {
$("body", w).append(mystuff);
});
raphael objects are set to a paper i think not shure what will happend when passing them betwen papers :S
精彩评论