JavaScript function to travel to a WEB Page : redirect()

January 31, 2008

In flex we use navigateToUrl () method to traverse to a WEB page, usually with a link Button or Button.

So how to do this with Javascript code behind the flex App, the solution is simple with a line a code.

The line is :

window.location.href=”";

specify the link in the double quotes.

Example:

In flex iam having Button which calls the function redirect() at JS,which contains the line of code, then definition would be as below..,

Code at Flex app:

<mx:Button id=”btn” click=”b()”/>

<script>

private function b():void

{

ExternalInterface.call(”redirect”);

}

</script>

Code at JS/html wrapper:

<script language=”javascript”>

function redirect()

{

 window.location.href=”http://www.google.com/”

}

</script>

Now on click Button the page will travel to the Google Page.