AS3 -- navigateToURL

Source: Internet
Author: User

NavigatetoURL () can be used to open a new browser window or communication between flex and JS, such as opening a new window:

 

Var url: URLRequest = new URLRequest ("http://www.eb163.com ");
NavigateToURL (url, "_ blank ");

 

 

This function can also be used to execute JS, for example:

VaR URL: URLRequest = new URLRequest ("javascript: window. Close ()");

 

Or:

VaR urllurlrequest = new URLRequest ("javascript: myfun (para1... Paran )")

 

The myFun () function is defined in the script part of the html page. function parameters must be enclosed in quotation marks!

NavigateToURL (url, "_ self ");

 

It can also be used to send an email:

 

Var urlURLRequest = new URLRequest ("mailto: 55555@163.com ");
NavigateToURL (url, "_ blank ");

 

 

 

Block navigateToURL pop-up window

 

Code

Package FlashCode. utils {
 
Import flash. display. Sprite;
Import flash.net. URLRequest;
Import flash.net. navigateToURL;
Import flash. external. ExternalInterface;
 
Public class openWindow {
Public function openWindow (url: String, window: String = "_ blank", features: String = ""){

Var WINDOW_OPEN_FUNCTION: String = "window. open ";
Var myURL: URLRequest = new URLRequest (url );
Var browserName: String = getBrowserName ();

If (getBrowserName () = "Firefox "){
ExternalInterface. call (WINDOW_OPEN_FUNCTION, url, window, features );
}
// If IE,
Else if (browserName = "IE "){
ExternalInterface. call (WINDOW_OPEN_FUNCTION, url, window, features );
// ExternalInterface. call ("function setWMWindow () {window. open (& apos;" + url + "& apos ;);}");
}
// If Safari
Else if (browserName = "Safari "){
NavigateToURL (myURL, window );
}
// If Opera
Else if (browserName = "Opera "){
NavigateToURL (myURL, window );
} Else {
NavigateToURL (myURL, window );
}

/* Alternate methodology...
Var popSuccess: Boolean = ExternalInterface. call (WINDOW_OPEN_FUNCTION, url, window, features );
If (popSuccess = false ){
NavigateToURL (myURL, window );
}*/

}
Private function getBrowserName (): String {
Var browser: String;

// Uses external interface to reach out to browser and grab browser useragent info.
Var browserAgent: String = ExternalInterface. call ("function getBrowser () {return navigator. userAgent ;}");

// Debug. text + = "Browser Info: [" + browserAgent + "]";

// Determines brand of browser using a find index. If not found indexof returns (-1 ).
If (browseragent! = NULL & browseragent. indexof ("Firefox")> = 0 ){
Browser = "Firefox ";
}
Else if (browseragent! = NULL & browseragent. indexof ("safari")> = 0 ){
Browser = "safari ";
}
Else if (browseragent! = NULL & browseragent. indexof ("MSIE")> = 0 ){
Browser = "ie ";
}
Else if (browseragent! = NULL & browseragent. indexof ("Opera")> = 0 ){
Browser = "Opera ";
}
Else {
Browser = "undefined ";
}
Return browser;
}
}
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.