Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15616] iOS: Hash value empty for local file system URL in WebView

GitHub Issuen/a
TypeBug
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.3
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterMarco Cota
AssigneeUnknown
Created2013-10-30T23:41:51.000+0000
Updated2018-02-28T20:03:34.000+0000

Description

Description:

User tried to load an html file located in the filesystem with an appended hash value (#value) but when trying to retrieve the value via window.location.hash this is null.

Test case:

Index.js

'use strict';

(function (e) {
  var url = Ti.Filesystem.getResourcesDirectory() + 'html/index.html#myHash';
  $.webView.url = url;
}());

$.index.open();

index.html

function updateHash() {
    document.getElementById('content').textContent =
      'url: ' + document.URL +
      '\nhash: ' + window.location.hash; 
}

Output:

[INFO] : url: file:///Users/mcota/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/2FA2A5DA-7AA4-4FFA-86F3-D634BD77BB39/WebViewHash.app/html/index.html [INFO] : hash:

Additional Comments:

This only happens when the url is from the local filesystem, when the url is an http:// address returns the hash value correctly.

Work-around:

Comments

  1. Shak Hossain 2013-11-15

    [~btran] - if a work-around was proposed to the customer, please post it to the JIRA.
  2. Betty Tran 2013-11-22

    The workaround we proposed involves setting the window.location.hash as part of a fireEvent. index.js
       var url = Ti.Filesystem.getResourcesDirectory() + 'html/index.html?#=myHash';
       
       $.webView.url = url;
         setTimeout(doEvent,2000);
         function doEvent(){
           Ti.App.fireEvent('webview>>hash',{hash:url.split('#')[1]});
         }
       
       main.js
       
       window.onhashchange = updateHash;
       
       Ti.App.addEventListener('webview>>hash',function(e){
       
           window.location.hash = e.hash;
         });
       
       function updateHash() {
           document.getElementById('content').textContent =
             'url: ' + document.URL +
             '\nhash: ' + window.location.hash;
         }
       

JSON Source