2 Replies Latest reply on Nov 8, 2009 12:25 PM by mewk

    How to implement a link to an external html-page at predefined size?

    mauro343

      Hi everyone!

      I hope u can help me!

      I´m trying to implement a link to an external html-page...But it´s important to open the link at a predefined window size, like a popup! I have found a code in the net but it´s not working. Perhaps someone can help me!


      That´s my code:

      protected function button_clickHandler_3():void


      {
      getURL("javascript:NewWindow=window.open('http://www.test.com','newWin','width=150,height=50,top=0, toolbar=No,location=No, scrollbars=No,status=No,resizable=No,fullscreen=No '); NewWindow.focus(); void(0);");
      }

       

      What´s wrong with the coding?

       

      Thanks a lot in advance

      Chris

        • 1. Re: How to implement a link to an external html-page at predefined size?
          mewk Level 3

          hey Chris,

           

          this is kind of a hack (it opens and the closes an intermediate window), but it should work. when compiling the code, make sure to use the latest nightly build of the SDK or else the bindings won't function properly.

           

          - e

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">
            <fx:Script>
              <![CDATA[
          
                [Bindable] public var myUrl:String = "http://google.com";
                [Bindable] public var myWinHeight:int = 500;
                [Bindable] public var myWinWidth:int = 500;
                [Bindable] public var myWinX:int = 0;
                [Bindable] public var myWinY:int = 0;
          
                public function openNewWindow():void {
                  /* e.g. new URLRequest("javascript:window.open('http://google.com',
                  'my new window','width=400,height=200,left=0,top=100,screenX=0,screenY=100', '_self');
                  window.close();"); */
                  var url:URLRequest = new URLRequest("javascript:window.open('" + myUrl +
                    "','my new window','width=" + myWinWidth + ",height=" + myWinHeight +
                    ",left=" + myWinX + ",top=" + myWinY + ",screenX=" + myWinX + ",screenY=" + myWinY +
                    "', '_self'); window.close();");
                  navigateToURL(url,"_blank");
                }
              ]]>
            </fx:Script>
            <mx:Form>
              <mx:FormItem label="url:  ">
                <s:TextInput text="@{myUrl}" />
              </mx:FormItem>
              <mx:FormItem label="window height:  ">
                <s:NumericStepper id="heightNS" value="@{myWinHeight}" minimum="0" maximum="1000" stepSize="50" />
              </mx:FormItem>
              <mx:FormItem label="window width:  ">
                <s:NumericStepper id="widthNS" value="@{myWinWidth}" minimum="0" maximum="1000" stepSize="50" />
              </mx:FormItem>
              <mx:FormItem label="window x-position:  ">
                <s:NumericStepper id="xNS" value="@{myWinX}" minimum="0" maximum="1000" stepSize="50" />
              </mx:FormItem>
              <mx:FormItem label="window y-position:  ">
                <s:NumericStepper id="yNS" value="@{myWinY}" minimum="0" maximum="1000" stepSize="50" />
              </mx:FormItem>
              <s:Button click="openNewWindow()" label="open new window" />
            </mx:Form>
          
          </s:Application>
          

          • 2. Re: How to implement a link to an external html-page at predefined size?
            mewk Level 3

            upon further testing, getting this code to be cross compatible with all browsers is a huge pain and you are going to have to fiddle around with certain properties e.g. _blank vs _self and whether to call window.close() or not.

             

            here are some observations:

            • Firefox: leave as is; seems to require window.close()
            • Chrome: needs navigateToURL(url,"_self") -- so i'd make this a requirement in the flex coding; also uses window.close()
            • I.E.: do not use window.close(). also (very important!!) you can't use spaces in the window.open() method call, so you need to change 'my new window' to something like 'myNewWindow'

             

            solution: use javascript to determine browser environment and then call appropriate javascript method.

             

            also, you can write your own *.js code and access it using the call() method -- if you don't want to write all the js code in your flex app that is...

             

            - e