I have a problem navigating to a Url in the default browser in an Adobe Air project.
air.navigateToUrl(request, windowName) launches the browser and displays the page, but it displays a new tab for every request.
Here is a very simple example that shows the problem:
Flex:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import flash.display.Sprite;
import flash.net.navigateToURL;
import flash.net.URLRequest;
protected function button1_clickHandler(event:MouseEvent):void
{
NavigateToURLExample();
}
public function NavigateToURLExample():void {
var url:String = "http://www.adobe.com";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, "testWindow");
}
catch (e:Error) {
// handle error here
}
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Button x="169" y="165" label="Button" click="button1_clickHandler(event)"/>
</s:WindowedApplication>
HTML:Javascript:
<html>
<head>
<title>navigateToURLTest</title>
<script type="text/javascript" src="lib/air/AIRAliases.js"></script>
</head>
<body>
<a href="#" target="testp" onclick="javascript:air.navigateToURL(new air.URLRequest('http://www.adobe.com'), 'TestWindow');return false;">Same Tab</a>
</body>
</html>
How can I open the url in the same window/tab?
Message was edited by: Karel VDH
Hi..
I am struck with the same issue as well.
It works for few sites like "http://www.adobe.com" and "http://www.google.com", but most of the sites open up in a new window, even if I specify custom name, like:
navigateToURL(new URLRequest("http://www.britishairways.co.uk"), "MyWindow");
Also tried through ExternalInterface viz:
ExternalInterface.call("window.open", new URLRequest("http://www.britishairways.co.uk"), "MySameWindow", "");
Please reply whether it is a bug, or there if there are any alternative approaches.
I'll ask around about this behavior and see if I can get additional info. In the meantime, would you mind creating a new bug on our online bug database? Please post back with a URL so others can comment and add their votes.
Thanks,
Chris
I have seomthing like this inside a class or package
function foo(event:MouseEvent):void
{
var result:String = ExternalInterface.call("callHome");
var fooURL:URLRequest = new URLRequest(result);
navigateToURL(fooURL, "_self");
}
logoButton.addEventListener(MouseEvent.CLICK, foo);
and this on every html page
<script type="text/javascript">
function callHome(){
return "http://localhost/fooproject/index.html";
}
This is a flash button of course I am not sure if it helps, but this worked out for me.
Thanks for your reply Karel!
Hi Chris,
I found this bug report made by Karel last year (https://bugbase.adobe.com/index.cfm?event=bug&id=2895041) Bug 2895041, but unfortunately, it was closed as not an AIR SDK issue.
I read Ru Wan's note, but in my opinion, that's not exactly the case. The navigateToUrl function should work exactly as a normal javascript 'window.open' - that's open in a new window if I specify '_blank' or in a specific window if the second parameter is saying so. Maybe you could reopen this issue.
Thanks in advance for your help.
Marcio
I'd recommend opening a new bug and try stating your case again. From what I've read, Ru's statement that this is a configuration preference of the browser appears to be correct. Regardless, if you do open a but It would really help if Karel and others affected take a minute vote for the bug and add their comments.
Hi Chris and Karel,
I opened a new bug report there - https://bugbase.adobe.com/index.cfm?event=bug&id=3199139
I think it may help if others could vote there or add notes.
Thanks,
Marcio
North America
Europe, Middle East and Africa
Asia Pacific