簡體   English   中英

Adobe AIR (html/javascript):navigateToUrl 的 window 參數不起作用

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

在 Adobe Air 項目 (html/javascript) 的默認瀏覽器中導航到 Url 時出現問題。

air.navigateToUrl(request, windowName)啟動瀏覽器並顯示頁面,但它會為每個請求顯示一個新選項卡。

這是重現問題的新 Air 應用程序中的主頁的一個非常簡單的示例:

<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>

如何在同一窗口/選項卡中打開 url?

您應該讓兩個錨點都指定相同的目標:

<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>

如果在您當前的選項卡列表中沒有打開名稱為"testp"的 window,它將打開一個新選項卡,如果您已經擁有它,那么它將被更改。

這段代碼對我有用:

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

應用於您的代碼:

<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>

請注意兩件事,rekaszeru 在 href 中添加了一個鏈接(不應該存在...與 target= 相同)第二,onclick 事件不需要“javascript:”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM