- Home /
Open link in new tab from webplayer hosted on any site.
I've searched this site and the unity script reference, but when it comes to linking I can only find out how to either:
change the page the web player is on to an other (I want it in a new tab. No killing my game! :p)
get unity to give the web page a command and then script into the web page how to respond to this command (by opening a link in a new tab)
What I want is to upload my game to a site I have no control over, yet when you click on a certain button a specified url will be loaded in a new tab. Why is this so hard and why does it seem no one has answered this before? o.O or am I missing something obvious?
TL;DR: Game on not my site. Click button. Open url in new tab. Help! :D
Edit: Still no complete answer, am I going to have to start a bounty? =p
Answer by efge · Mar 02, 2011 at 09:46 PM
Try this:
Application.ExternalEval("window.open('http://www.google.com','_blank')");
(You have to disable pop-up blockers.)
I'm looking for a way to open things in a new tab, not a new window. But thanks for trying to help though! :D
It opens a new tab (tested: Firefox on $$anonymous$$ac) and it is the complete http code.
Oh you are absolutely right! $$anonymous$$y apologies, I didn't notice the '_blank'. Thanks again! :D
Answer by JGeorge · Mar 02, 2011 at 04:11 AM
http://unity3d.com/support/documentation/ScriptReference/Application.OpenURL.html
I'm having trouble seeing what you are asking, but I think this will do what you need.
It opens a new tab within your default browser. The url it goes to is what you provide in the parameter.
Edit: Try this command: Application.ExternalEval("window.open('httpcodehere')");
This opens an url in the current tab. That's exactly my problem.
Let me try to be more clear: The game is player by the webplayer on a website. If I execute this command the website will be changed. That's the whole point of 'different tab' or pop-up of course.
But thanks for trying to help! Just reread my comments and may have sounded a bit harsh, if so: that wasn't my intention. :)
Try this command:
Application.ExternalEval("window.open('httpcodehere')");
Thanks a lot! Not a perfect solution, since this creates a pop-up (which will be blocked) ins$$anonymous$$d of a new tab, but at least it works! If you edit this into your main answer I'll change my -1 to a +1 :D right now it says "value to old to be changed, unless this answer is edited"
Answer by by0log1c · Mar 02, 2011 at 04:40 AM
This really isn't the most interesting solution but if the page you are trying to access is your own. You could use the html/javascript to open the pop-up and load the game back. Resuming a game mid-play would require quite some trickery I guess.
Can't wait for actual working answers you guys got ;)
:-) that's at least a little helpful. Thanks! Oh and seeing how this question is now 9hours old and still unanswered it would probably help if you'd up-vote the question so the bot bumps it up. ;)