开发者

Adobe AIR history.back() doesnt work when calling from html javascript

开发者 https://www.devze.com 2023-04-07 09:42 出处:网络
I\'m working on air app (html/ajax/javascript). I need to make a navigation feature, like a browser back and forward button in a page with iframe, all pages are on same domain.

I'm working on air app (html/ajax/javascript). I need to make a navigation feature, like a browser back and forward button in a page with iframe, all pages are on same domain.

I have the following scenario:

Adobe AIR (version 2.7.1) app that loads (air.HTMLLoader) index.php from mydomain.com

http://mydomain.com/index.php file has following design:

<html>
    <body>
        <input type="button" value="< BACK" onclick="iframeID.history.back();">
        <input type="button" value="FORWARD >" onclick="iframeID.history.forward();">
        <ul>
            <li><a href="http://mydomain.com/page1.php" target="iframeNAME">page 1</a></li>
            <li><a href="http://mydomain.com/page2.php" target="iframeNAME">page 2</a></li>
        </ul>
        <iframe src="page_default.php" id="iframeID" name="iframeNAME"></iframe>
    </body>
</html>

So, this code works in FireFox, Chrome, Safari, but not in Adobe AIR app

I can't find any documentation about this issue, really cant understand where开发者_开发知识库 is the problem, as i know adobe air uses webkit for web pages browsing like chrome and safari but only in air app this code doesnt work.

I hope someone can help me.

Thanks!


My app is basically an HTML site in dreamweaver with flash intros, and linked navigation between HTML pages, which is then converted into an air app.

All HTML files are in the same directory. So page2.html is in the same root site folder as page3.html. Some of my pages require navigating back to the previous page. However, because you could arrive at that page through various paths, I really needed the back capability. So after struggling through alot of very complex suggestions, I dropped this very basic example from w3schools in:

<html>
<head>
<script type="text/javascript">
function goBack()
  {
  window.history.back()
  }
</script>
</head>
<body>

<input type="button" value="Back" onclick="goBack()" />

</body>
</html>

And it works. For my app, it works in all browsers, and as a desktop AIR app for Mac and windows. I'm just working my way into air, but I thought this might help you fix your problem.


I feel like you have a few concepts mixed up. So I will try to help.

First, is the statement: "all pages are on same domain"

There is no domain in an Adobe AIR application. You are not browsing http://localhost/. You are loading a file fromt he file system and it is being rendered as HTML. There are no URLs in AIR (unless you are accessing a remote system) so, as I understand it, history.back() is not going to work.

Second, I am concerned about these lines:

<li><a href="/page1.php" target="iframeNAME">page 1</a></li>
<li><a href="/page2.php" target="iframeNAME">page 2</a></li>

Those are not going to render. AIR does not have PHP support built in. And like I said, AIR is browsing http://localhost, so your local PHP install (if you have one) is not going to parse and process those files before they are delivered to AIR.

Building desktop applications is very different than building web applications. And relying only on HTML and JS presents some challenges. You lose a lot of the benefits of a server-side solution like PHP or ColdFusion. There's no session store, there are no cookies (except for when accessing remote services), there are no URL parameters, etc.

You do pick up a lot of additional benefits with AIR though. You have access to the local file system, you get an encrypted local store, you are not restricted by the same-origin policy of the browser, you can use a local database (even an encrypted one), and much more.

If you really need to browse and render PHP files from within an iframe in AIR and you need to have a back and forward button, then you'll need to host the PHP somewhere remotely (or have all of your users install it locally) and you'll need to have that iframe call the page remotely. Then I suspect that history.back() would work.

You could create your own back/forward functionality simply by storing the history of the pages being viewed using one of AIRs many local storage options (ELS, StorageObject, SQLite, File System) and then implement back and forward buttons that use those stores to reload content. But I think the better option is to simply have quality navigation in your application.

Good luck.


In AIR applications are "sandboxes" based on where content is loaded from. Your main application is in the "application sandbox" and remotely loaded content is in the "non-application sandbox". Each sandbox is restricted as to what it can do.

Content in each sandbox cannot talk to content in another sandbox without a bridge. Since you are loading your iframe with remote content your application-sandboxes HTML file that is trying to access it is likely being restricted.

I think you need to look into what is called a sandbox bridge. Specifically a parent-to-child sandbox bridge.

I did a presentation on that once. The slides are available on my blog. . I would give you a direct link, but I am on my phone. Just search for AIR Security or CFUnited 2010.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号