AddToJavaScriptWindowObject('location') problem



  • I'm trying to make a standalone loader for a (online) flash game.
    It's a little simple to make it working.

    I need to pass a "fake" (the original game url) to the flash, and not the current url.

    But i have some problems:

    When it's loading, the flash app calls:

    ExternalInterface.call('window . location.href.toString');
    //using spaces because the forum use a [removed] replace for it.

    To get the url, and if the url have "?salon=roomname"
    (i think it's only this part of url that the flash handles)

    It will get the room name, and automatically connects to it, if the flash don't find "salon" in the url, it will connect you to a random room.

    It's here my problem:

    • I'm using <embed> to load the flash in QWebView, and using setHtml() set the window . location.href to "about:blank".

    This happens even if i load the game page in QWebView and try to change it's source (and i don't want to do this, this will load more content... i can try to making it by javascript evaluation, but... it's a "ugly" solution too...)

    • I've tried to "overload" the window . location object, i think, if i set a "fake" window . location, i can send the fake url to the flash. But, there's another problem:

    When I use addToJavaScriptWindowObject('location', new FakeLocation("shadow's room")) it "broke" my QWebView and the flash don't load.

    I've tried to check by javascript alert, and it's not showing the alert, so, addToJavaScriptWindowObject is preventing me from changing the html or crashing the QWebPage.

    But, what made me to try too much times is:
    if I change addToJavaScriptWindowObject('location', new FakeLocation("shadow's room")) to
    addToJavaScriptWindowObject('FakeLoc', new FakeLocation("shadow's room")) it works.

    • With a last try, i've overloaded the String.prototype.toString() with this:

    if (this == window . location.href) return window.FakeLoc.href;
    else return this;

    I know it isn't a good solution but, if worked at least i don't need to make "loading tricks", but this isn't working too.

    Even if a javascript alert shows the FakeLoc.href, the flash game isn't getting my fake url by the external interface call.

    • And I'm really sure the game use that ExternalInterface.call('window . location.href.toString');
      Because in C# when I use the FlashCall event I can get it and return the url.

    • Someone can help me with this ? What I can try now ? Is something that I've tried is wrong ?
      There's a way to get a pointer to js window object or window . location object inside Qt ?
      Is there a way wait external flash calls and respond to it by events ?

    Thanks for reading, and for helping if you help ^^
    Have a nice day,
    and thanks again.

    Sorry for the big question and sorry for the bad english.



  • @shadownt I understand that the answer is a bit late, but maybe it will help someone. You can use the second parameter in QWebView::setHtml

    m_webView->setHtml( "html content here", QUrl("http://google.com"))

    now the window.location will have the following value:
    {
    Location
    hash: ""
    host: "google.com"
    hostname: "google.com"
    href: "http://google.com/"
    origin: "http://google.com"
    pathname: "/"
    port: ""
    protocol: "http:"
    search: ""
    proto: LocationPrototype
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.