0

I have one variable in .aspx code and i want to use it in my .js code.

How to make this work?

In .aspx code..

var url = document.referrer;
var res = url.split("?");
var str = res[1];

So I want the str to be used in my .js code..

  • 1
    What is that variable? Can you please share the snippet? – Asad Refai Oct 13 '15 at 9:12
  • Use session or viewstate. – Kaushal Khamar Oct 13 '15 at 9:26
  • where does your .js file locate? in .aspx file? – Atish Dipongkor - MVP Oct 13 '15 at 9:32
  • @AtishDipongkor .js is a different file in visual studio – KumarV Oct 13 '15 at 9:36
  • So where have you referred it? I mean where did you give script tag? – Atish Dipongkor - MVP Oct 13 '15 at 9:38
6

That code is not ASPX code. It is JavaScript code (inside a Script block in your ASPX file?)

If it is not a Global variable yet, you can declare it as window.js=res[1] to force it in the global scope (and thus available to all other functions)

Time to read about Javascript Variables, Closures etc. :

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.