Welcome, Guest

Author Topic: 404 Not found  (Read 1319 times)

Jaho

  • Posts: 6
    • View Profile
404 Not found
« on: December 05, 2013, 08:25:13 AM »
- How can I know if a page exists? If I use a non existing url I just see a blank page. I must make sure that a user went to a valid page.

/Jaho

Nick

  • Administrator
  • *****
  • Posts: 475
    • View Profile
Re: 404 Not found
« Reply #1 on: December 06, 2013, 01:29:05 AM »
You can listen for the FailLoad/FinishLoad events in the ViewListener.

Here's some sample code that you can add in a component:
Code: [Select]
void Start()
{
CoherentUIView viewComponent = Camera.main.GetComponent<CoherentUIView>();

viewComponent.Listener.FailLoad += (frameId, validatedPath, isMainFrame, error) =>
{
Debug.Log ("Error when loading URL \"" + validatedPath + "\": " + error);
};

viewComponent.Listener.FinishLoad += (frameId, validatedPath, isMainFrame, statusCode, headers) =>
{
if (statusCode == 404)
{
Debug.Log ("URL \"" + validatedPath + "\" cannot be reached!");
}
else
{
Debug.Log ("URL \"" + validatedPath + "\" loaded with code " + statusCode);
}
};
}

The FailLoad event is fired when some generic error occurs, e.g. if you try to access http://asdfasdfasdfdas.asd while for 404 errors you can use FinishLoad (e.g. try http://www.msn.com/dingdong).
R&D Director @CoherentLabs

Tags: