How to copy mouse position on a div on top of cocos div to in game's cursor position

Hi, I need to create a div on top of the game to create a href button. but doing that I lose the hover effect on my in-game button, anyway I can make the in-game cursor to track the mouse movement of the div too?


1 Like

Do you really need that href button? The CC button callback could not do the trick?

If not mistaken iPhone doesn’t allow that unless is from an a href

Native app or browser? For both cases, my games work with button flawless

hmm… maybe I’m overthinking it, which code are you using and does it work on iPhone safari?
I need it to open for new window too, thanks~


Just to be sure, I don’t know if you already know that, but in the button property you add a click event, drag the node that contains the code that will be called (can be the same or other node), select the script in the first dropdown, and the function in the second.

To open another tab you use cc.sys.openURL(url);

Keep in mind that Apple don’t like you to open browser when the app is downloaded from the store (if you only will work with safari, that’s fine, ignore this), so try to add as many as features possible in your app. If you must open in the browser (I had), add a warning that you are leaving the app to open the browser

Cool thanks, is the warning that you are leaving the app something that needs to be done inside cocos?

yes, I’ve done a popup with OK/Cancel buttons

Cool, will try that. Thanks!

Hmm… one more thing, is it possible to open URL in the same window/tab of the game?

Yes, just call it as if was a default web application

Is there a cocos way for this? otherwise I’ll need to add the a href in order for safari to work, the div will take away the mouse move

Now I’m not getting what you are trying to do.

You want to redirect the user from your game’s page into another page, but still want your button to work?

Or you want to call an iframe-like website inside your game?

If it’s the last, CC has one component that will do that, if it’s not, please explain me more

I just want to redirect the user from my game’s page into another page in the browser, but I need it to work in safari too.