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.

<formname="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><bodyonload="document.myform.mytextfield.focus();"><formname="myform"><inputtype="text"name="mytextfield"onchange="checkForm()"></form><scripttype="text/javascript"language="JavaScript">functioncheckForm() { 
    var field1 = document.forms['myform'].elements['mytextfield'].value; 
    alert(field1);
    window.location.assign(field1);
    returnfalse;
}    

</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"