cancel
Showing results for 
Search instead for 
Did you mean: 

Handle Hashtag change

joao_sousa2
Active Contributor
0 Kudos

I want to handle a hashtag change in my SAPUI5 app. For examples sake, let's say I want to throw a popup with the value of the hashtag, what's the correct way to do it?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

jmoors
Active Contributor
0 Kudos

Hi Joao,

I think you can use the sap.ui.core.routing.HashChanger to attach an "hashChanged" event handler.


var oHashChanger = HashChanger.getInstance();

oHashChanger.attachEvent("hashChanged", function(oEvent) {

  alert(oEvent.getParameter("newHash") + "," + oEvent.getParameter("oldHash"));

});

https://sapui5.netweaver.ondemand.com/sdk/#docs/api/symbols/sap.ui.core.routing.HashChanger.html

Regards,

Jason

joao_sousa2
Active Contributor
0 Kudos

I'm trying to use your code in the onInit of the view controller, but I'm getting a "Uncaught ReferenceError: HashChanger is not defined"

Am I missing something?

joao_sousa2
Active Contributor
0 Kudos

I was missing the "Jquery.require" but now I change the hash and nothing happens.

joao_sousa2
Active Contributor
0 Kudos
  1. var oHashChanger = HashChanger.getInstance(); 
  2. oHashChanger.init();
  3. oHashChanger.attachEvent("hashChanged", function(oEvent) { 
  4.   alert(oEvent.getParameter("newHash") + "," + oEvent.getParameter("oldHash")); 
  5. }); 

I needed to add step 2. Now it works.

Answers (0)