简体   繁体   中英

Adobe AIR (html/javascript): navigateToUrl's window parameter not working

have a problem navigating to a Url in the default browser in an Adobe Air project (html/javascript).

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 of the main page in a new Air application that reproduces the problem:

<html>
    <head>
        <title>navigateToURLTest</title>
        <script type="text/javascript" src="lib/air/AIRAliases.js"></script>        
    </head>
    <body>      
        <a href="#" 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?

You should have both of your anchors to have the same target specified:

<html>
    <head>
        <title>navigateToURLTest</title>
        <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
    </head>
    <body>
        <a href="http://www.google.com" target="testp"
            onclick="javascript:air.navigateToURL(new air.URLRequest('http://www.adobe.com'), 
            'TestWindow');return false;">New Tab</a>
        <br />
        <a href="http://www.adobe.com" target="testp"
            onclick="javascript:air.navigateToURL(new air.URLRequest('http://www.adobe.com'), 
            'TestWindow');return false;">Same Tab</a>
    </body>
</html>

If no window with name "testp" is opened in your current list of tabs, it will open a new tab, and if you already have it, then it will be changed.

this code works for me:

navigateToURL(new URLRequest("http://www.adobe.com"), '_self');

applied to your code:

<html>
<head>
    <title>navigateToURLTest</title>
    <script type="text/javascript" src="lib/air/AIRAliases.js"></script>
</head>
<body>
    <a href="#" onclick="air.navigateToURL(new air.URLRequest('http://www.adobe.com'),'TestWindow');return false;">Same Tab</a>
</body>
</html>

Please notice two things, rekaszeru has added a link in the href ( which should not be there... same with target= ) second, the onclick event does NOT need the "javascript:"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM