开发者

invoke javascript function from another page

I am developing a mini "ping pong" game with Javascript. The players will use the keyboard of their computers to control the game.

I would like to add an extra feature. I want the user be able to control the game from a smartphone. The user will open a mobile browser and type a url. This mobile page will track the gestures and then will invoke the Javascript function that moves the ping-pong racket.

So, the game runs on PC browser and users will control the racket from their mobile phones browser.

How can i invoke a javascript function that exist in page1.html, from page2.ht开发者_如何转开发ml


You're going to need some server side logic to handle this. There are ways to make two pages talk to each other, but they need to be inside the same browser window (like frames or iframes). In your scenario, they're on completely different devices. You will need some sort of dynamic server (which can serve PHP/Python/etc. scripts) so that the javascript on the device can report back to the server, and the server can report to the javascript code on the PC.


Could you not include the javascript .js file in the html for both pages? There by being able to call it from both?

i.e. use this on both pages.

<SCRIPT LANGUAGE="JavaScript" SRC="[filename]"></SCRIPT>


i think you want to call the same function from both pages. For this create a .js file and add that function to it. Include the js file in both page and call the function from both pages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜