0

I have been searching for this for hours, found many ways but no idea why doesn't any of them works..

code :

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/test.js"></script>

</head>
<body>
    <label id="res"></label>
    <script type="text/javascript">
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
        return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    function crypt() {
        var ex = getParameterByName('eX');
        var er = getParameterByName('eR');
        var aaa = Aes.Ctr.encrypt(ex, er, 256)
        document.write(aaa);
        document.getElementById('res').innerHTML = aaa;
    }
    window.onpaint = crypt();
    </script>

</body>
</html>

What i'm trying to do is to read params from the URL and then run some JavaScript code using these params, then print result in the page.

tried to put the JS code in head, tried onload event, tried addeventlistner, and other stuff, still no luck(on HTML and ASP). all works after page load completes.

but it must be done before page loads completely..

Thanks.

Dr.Vision
  • 85
  • 1
  • 5
  • 14
  • 1
    you can see how parameters are accessed in javascript here : http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter – arkoak Mar 20 '15 at 11:31
  • Wow, classic ASP...Jesus this still exists :) I'm not clear what bit your stuck on? – Liam Mar 20 '15 at 11:31
  • i have no problems with getting params from the URL, the problem is that the JS executes after page load completes.. – Dr.Vision Mar 20 '15 at 12:17
  • If it's classic asp couldn't you use the request object, eg `var ex = <%= Request.Querystring("eX") %>');` – John Mar 20 '15 at 13:02
  • @John i have no problems with getting params from the URL, the problem is that the JS executes after page load completes.. – Dr.Vision Mar 20 '15 at 13:04
  • You could try using ` – John Mar 20 '15 at 13:08
  • that turned all JS code to errors, no idea why.. anyway now i'm trying to do it with just a HTML page.. – Dr.Vision Mar 20 '15 at 13:29
  • any help with HTML page ?! – Dr.Vision Mar 22 '15 at 16:27

1 Answers1

0

You can use document.onreadystatechange event that will be executed just before document.onload will execute

document.onreadystatechange = function(e)
{
    if (document.readyState === 'complete')
    {
        //Here you may write your code, after this document.load will fire
    }
};
Mox Shah
  • 2,967
  • 2
  • 26
  • 42