Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

how to hide user id and password from URL in JavaScript?

Hello Everyone, is there any way I could hide 'userid=parthad&password=abcd123' from showing it in address bar on my onClick function? Thank you.

<a id="collabLink" href="link" onClick="javascript:window.open(
'index.html?userid=parthad&password=abcd@123','toolbar=no,menubar=no,resizable=yes,location=no,directories=no,status=no');return false")">
    <button type="button" class="btn btn-primary" style="position: fixed; margin: auto; left: 0; right: 0; top: 0; bottom: 0; width: 150px; height: 40px;">
        Launch Collab
    </button>
</a>

2 Answers

Steven Parker
Steven Parker
243,253 Points

To conceal your parameters you need to use the POST method instead of GET, but I don't think that's an option in window.open.

You might try constructing a form object with your URL as the action, a new window as the target, and child input elements for the parameters and then calling the "submit" method on it.

Oh Hi Steven Parker...interesting suggestion..I will definitely look on it..thanks once again and Happy new year...:)

I think the only way is to use AJAX (XHR) with POST method.

Thanks @Andrey Misikhin, yes I did try to use AJAX but it doesn't work for me...:(