Getting current URL in Flash from JavaScript using ExternalInterface and IE

前端 未结 4 1968
情歌与酒
情歌与酒 2021-01-15 13:54

I\'m trying to get the current URL that the Flash player is on. Not the URL of the .swf file, but the URL that the browser is pointing to. Thus far I\'ve used:



        
相关标签:
4条回答
  • 2021-01-15 14:20
    ExternalInterface.call('window.location.href.toString');
    
    0 讨论(0)
  • 2021-01-15 14:29

    Just a suggestion:

    That is likely because IE has, for some reason, decided that window.location.href can be used as a function. It is asinine, but that is Microsoft for you.

    Have you tried ExternalInterface.call( "String", "window.location.href" )? That would be my next guess.

    0 讨论(0)
  • 2021-01-15 14:41

    Have you given any thought to achieving what you want without an External Call.

    var domain:String = loaderInfo.loaderURL;
    trace(domain.substr(0, domain.indexOf("/", 8))); //Searches for first instance of "/" after the 8th character.
    

    Above, we trace out the base domain using indexOf to make a sub-string from the full path to the swf. We search for the first instance of "/" after the 8th character to return the end point of the substring. The reason we go in 8 characters is to allow for http:// and https://; we need it not to see those first "/"'s. I tested this and it worked great.

    There is nothing wrong with ExternalInterface calls, but I tend to save them for when required.

    0 讨论(0)
  • 2021-01-15 14:46

    You need a couple of things in order to make it work in IE. First the ActionScript:

    var domain:String = ExternalInterface.call('function () { return window.location.href; }');
    

    Second, you need valid classid and id atributes in the <object> tag:

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myplayer_123123" ...>
    

    If you don't put those attributes, ExternalInterface.call always returns null in IE6/7/8 but works as expected in firefox.

    Third, you need to set the param allowScriptAccess to 'always', in order to enable the use of ExternalInterface.

    <param name='allowScriptAccess' value='always'/>
    ..
    <embed allowscriptaccess='always' ...>
    

    .....

    0 讨论(0)
提交回复
热议问题