0

Case is that:

  1. My script inserts <script> in <head>, pointing to src1.

  2. The back-end does 307 redirect from src1 to src2.

  3. Script then loads src2.

But when I use this code, I'm getting src1.

var s = document.createElement("SCRIPT"), 
    h = document.getElementsByTagName("HEAD")[0]; 
    s.charset = "UTF-8";
    s.src = url;
    s.async = true;
    s.type = "text/javascript";     
    h.appendChild(s);
    s.onload = function() {
      console.log(this.src)
    }

How can I get the src2?

Joseph
  • 117,725
  • 30
  • 181
  • 234
Maksim Slepov
  • 81
  • 1
  • 4
  • You might want to check if the redirect is still in effect. If you happened to test this and then switched on redirection, your browser might be using a cached version of the resource. – Joseph Jul 16 '15 at 12:44

1 Answers1

0

this.src is the src url you have set on your script tag, what you get back is the source from the temporarily redirected (307) script.

If you visit the src1 url and copy the redirect url from the response using fiddler or dev tools on your browser, you can set the that url directly in your code.

BhavO
  • 2,406
  • 1
  • 11
  • 13