Edgar Navasardyan Edgar Navasardyan - 7 months ago 39
Javascript Question

Django - passing parameters to GET method when using JS window.open() function

I Have the following JS script which opens a new window and renders a Django template corresponding to


function draw_comparing_graphs()
window.open('/my_url/', '_blank', 'location=yes,height=570,width=1500,scrollbars=yes,status=yes');

Now, the question is, how do I pass on parameters to Django ? I mean, what is the equivalent of
$.post('/my_url/', data)


Since you're just opening a page, using POST is not an easy option (you could by having it automatically submit a form from /my_url/, but I wouldn't recommend it). You could easily append some GET parameters to /my_url/ though. Something like: `/my_url/?json=...your-json-data...

Within Django you can reach this using request.GET['json']

Example with your code:

function draw_comparing_graphs()
    window.open('/my_url/?json=' + encodeURIComponent(json_data), '_blank', 'location=yes,height=570,width=1500,scrollbars=yes,status=yes');