[ad_1]
I request a username using a prompt within my index.html. My code looks like this:
<script>
// YOU DO NOT NEED TO EDIT THIS CODE
if (!/(&|?)username=/.test(window.location.search)) 'anonymous';
console.log("From Index.html:" , username);
newSearch += 'username=' + (username);
window.location.search = newSearch;
</script>
I need to access this username within my app.js. I am sending a POST request to a server that requires the username as a property. For example:
//POST the message to the server
handleSubmit: function()
var query = window.location.search;
var username = query.slice(10, query.length);
var room = $('#roomSelect').find(':selected').text();
var msg =
username: username,
text: $('#message').val(),
roomname: room
;
app.send(msg);
console.log(msg);
app.renderMessage(msg);
Essentially, I want to prompt the user for their username in the index.html, but how do I access this variable from the app.js? Do I send it back to that file somehow?
[ad_2]
لینک منبع