Search Unity

Opening a browser windoe with a collision

Discussion in 'Scripting' started by groovista, Feb 12, 2008.

  1. groovista

    groovista

    Joined:
    Feb 15, 2007
    Posts:
    21
    I'm trying to implement a simple in-game advertising gag, so that when you crash into a billboard a new browser window is opened and a specified URL is loaded. I get the idea but not the syntax. Here's the script attached to the billboard:

    Code (csharp):
    1. function OnCollisionEnter(collision : Collision) {
    2.     //Call Javascript function in HTML document to open an external site
    3.     Application.ExternalCall("OpenURL_groovium");
    4. }
    And here's the code on the webplayer page:

    Code (csharp):
    1. <script language="javascript1.1" type="text/javascript">
    2.     function OpenURL_groovium()
    3.     {
    4.          PauseGame();
    5.              //hide unity          
    6.              GetUnity().SetSuspended(true);
    7.          //open new window at URL          
    8.              open("http://www.groovium.com/");
    9.     }
    10.  
     
  2. ChromeFly

    ChromeFly

    Joined:
    Nov 4, 2007
    Posts:
    60
    Is there a particular reason why you can't use
    Code (csharp):
    1. Application.OpenURL("http://www.groovium.com/");
    ?

    Edit: Nevermind, I just realized you are running a web player and want a new window.
     
  3. podperson

    podperson

    Joined:
    Jun 6, 2006
    Posts:
    1,371
    It seems like what you're doing should work just fine.

    It may get blocked by popup blockers. (In general, the way web browsers try to detect popups is by filtering requests from plugins for new windows that aren't considered to have been a consequence of a mouse click.)