I create a link that calls the javascript function in the href attribute:
<a class="product-link" target="_blank" href='javascript:functionToPostParameters("path", "parameters");'><span class="product-name">My Product Link</span></a>
My function is this:
function functionToPostParameters(path, params) {
var form = document.createElement("form");
form.setAttribute("method", "post");
form.setAttribute("target", "_blank");
form.setAttribute("action", path);
for (var key in params) {
if (params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}
form.submit();
return false;
};
When I use this link in Chrome, it calls a function, submits a form with parameters and opens a new tab.
A new tab opens in Firefox, and then the function is called, since the new tab does not contain the function, this error is displayed in the console of the new tab:
ReferenceError: functionToPostParameters is not defined
Is there an error in the href value / js function that makes Firefox this way?
Any approach is appreciated using href for reference.
source
share