How to get the referrer HTTP address at the Gwt entry point

I Could not find any class / method that gives me access to the referrer header in GWT. Does anyone know about this?

+4
source share
5 answers

Cm

Document.get().getReferrer() 
+7
source

Since you cannot get headers in javascript, I don't think you can get them in the GWT client: Accessing the HTTP headers of a web page in JavaScript

Update:

Perhaps you can update login.php to write the referrer to a hidden input tag, maybe something like this:

 <input type="hidden" name="referrer" name="referrer" value="<?php Print referrer_value ?>"> 

Then in gwt you can get the value using something like this:

 InputElement elt = (InputElement)Document.get().getElementById("referrer") String referrer = elt.getValue() 

Note. This is untested code, and I'm not even sure if this is valid php, but hope this helps!

+2
source

I had the same question, but I made some changes to charge the title bar tag dynamically. I used this code:

 LinkElement link = Document.get().createLinkElement(); link.setHref("css/home.css"); 

I don't know if this is the most elegant solution, but it works!

EDIT: If you need to change any current item, you must do this:

 NodeList<Element> links = Document.get().getElementsByTagName("link"); for(int i = 0; i < links.getLength(); i++){ LinkElement l = (LinkElement)links.getItem(i); if( l.toString().contains("href_to_replace.css") ){ l.setHref("new_href.css"); break; } } 
0
source

You can access the referrer in JavaScript and pass it to Java (rather, JavaScript compiled with Java). You need to define a JSNI (JavaScript Native Method) method in Java with a JavaScript definition. This code can access document objects and browser windows, although you need to use the $ doc and $ wnd variables for this purpose. Additional information in

https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI

0
source

You can get the full URL string like this:

String url = Document.get (). getURL ();

get the question mark index and analyze it yourself

0
source

Source: https://habr.com/ru/post/1336189/


All Articles