Highlighted

stagewebview changing preventDefault

Explorer ,
Jul 26, 2016

Copy link to clipboard

Copied

I have a stagewebview using the native browser. I have an event listener on LOCATION_CHANGING.  In the location changing event I trace the new location and also call event.preventDefault();.

The function is getting called as I navigate the page because I am getting my new location url trace but the event.preventDefault is not stopping the page from changing. Shouldn't that prevent the page from actually navigating to the new url?

TOPICS
Development

Views

831

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

stagewebview changing preventDefault

Explorer ,
Jul 26, 2016

Copy link to clipboard

Copied

I have a stagewebview using the native browser. I have an event listener on LOCATION_CHANGING.  In the location changing event I trace the new location and also call event.preventDefault();.

The function is getting called as I navigate the page because I am getting my new location url trace but the event.preventDefault is not stopping the page from changing. Shouldn't that prevent the page from actually navigating to the new url?

TOPICS
Development

Views

832

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 26, 2016 0
Adobe Community Professional ,
Jul 26, 2016

Copy link to clipboard

Copied

Yes it should stop it. Can you show your code?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2016 0
Explorer ,
Jul 26, 2016

Copy link to clipboard

Copied

Below is my code. I am on a mac, I tried air 21 and 22 with the same result. I get my trace but the webpage continues to navigate.

webView = new StageWebView(true);

webView.stage = this.stage;

webView.viewPort = new Rectangle(0,0, _stageWidth, _stageHeight);

webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, getWebViewData);

webView.loadURL(fileURL);

private function getWebViewData(event:LocationChangeEvent):void

  {

  event.preventDefault();

  trace(event.location);

}

javascript in the html calling the page change

window.location.href = 'http://etherdcp.com?type=save&name=test';

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 26, 2016 0
Explorer ,
Jul 27, 2016

Copy link to clipboard

Copied

So I found a strange work around. If I have a valid web url like http://etherdcp.com?type=save&name=test then I cannot prevent the page from changing (event.preventDefault). If I change the url to e://e.com?type=save&name=test , then I am able to prevent the page from changing and still trigger the location_changing event. This work around will work in my case because I am simply trying to grab the parameters. I hope this helps someone else.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 27, 2016 0
Explorer ,
Jul 27, 2016

Copy link to clipboard

Copied

looks like even if I don't call preventDefault() when using an invalid url like e://e.com?type=save&name=test, the page doesn't change. I am not sure how other systems will handle this.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 27, 2016 0
heilong LATEST
Community Beginner ,
Nov 30, 2017

Copy link to clipboard

Copied

Your workaround seems to work, but it's not without faults.

The page I'm hosting in a webview does some XHR network requests, when one of them completes I want to notify my AS code, using LOCATION_CHANGING event listener (and an invalid url like in your example, or `#data=....` url which also works). However, preventDefault() doesn't work correctly, and the other ongoing active XHR network requests are canceled (they return status code 0).

This breaks the functionality of the JS library I'm using.

I'm thinking about making a primitive WebSocket server in AS (using SocketServer) on 127.0.0.1, then connecting to it from JS and using that as JS-to-AS communications channel.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2017 0