开发者

Escaping "/" doesn't work in IE9

I have a javascript function that builds an URI fragment using some captured parameters, and then submits my form.

Example:

function consultResource(contextName){
    var form = document.forms[0];
    var f1 = form.thename.value;//accepts strings without special symbols
    var f2 = escape(form.thedate.value); //accepts only strings in the form 'dd/mm/yyyy'
    var action = "/"+contextName+"/CtrlComparison?name="+f1+"&date="+f2;
    form.action = action;
    form.submit(开发者_如何学Python);
}

An example generated URI fragment would be

/MyContext/CtrlComparison?name=report01&date=06/05/2011

This snippet works, submitting the form and bringing a PDF document OK for:

  • Firefox 3.x-4.x (not tested on 2.x)
  • Internet Explorer 6-8
  • Google Chrome 9.x-11.x (other versions not tested)
  • Opera 10.x-11.x (other versions not tested)

But I need it to work in Internet Explorer 9 too. Currently when I submit the same info in IE9 I get the following message:

Escaping "/" doesn't work in IE9

instead of something like this:

Escaping "/" doesn't work in IE9

IE9 is not escaping the / and taking them as part of path separators on URI.

The question is: How could I get my URI fragment to be correctly generated in IE9 too?

Thanks in advance.


This is not a problem with your form, or action URL. You need to send the correct headers when you write out the PDF.

In your php header("Content-disposition: attachment; filename:comparativoCajasRegistradas.pdf");


You may want to try encodeURIComponent instead of escape for the query parameter values.

The encodeURIComponent() function encodes a URI component.

This function encodes special characters. In addition, it encodes the following characters: , / ? : @ & = + $ #


Escape function encodes special characters, with the exception of: * @ - _ + . /. So replace it on client-side then put it back on server-side.

JS

var f2 = form.thedate.value.replace(/\//g, "x");

JAVA

f2 = f2.replaceAll("x", "/");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜