Skip to content Skip to sidebar Skip to footer

Javascript - Window.location.assign Not Working

I've a project where I scan a QR code, and it will then automatically print out information based on which code was scanned. I have the scanner, and a printer. Each QR code is to c

Solution 1:

Looks like the form is submitting. Cancel it.

<form name="myform" onsubmit="return false">

Solution 2:

You want:

window.location = field1;

Solution 3:

add return false; after window.location.assign(field1);

 <html>
<head><title>QR Printing</title></head>

<body onload="document.myform.mytextfield.focus();">

<form name="myform">
    <input type="text" name="mytextfield" onchange="checkForm()">
</form>

<script type="text/javascript" language="JavaScript">

function checkForm() { 
    var field1 = document.forms['myform'].elements['mytextfield'].value; 
    alert(field1);
    window.location.assign(field1);
    return false;
}    

</script>

</body>
</html>

Solution 4:

Neither of the solutions worked for me in chrome browser. I have resolved this using:

setTimeout(function () { document.location.href = YourUrlLink }, 500);

Hope this helps who are seeking a solution for chrome browser issue.


Post a Comment for "Javascript - Window.location.assign Not Working"