2011-12-08 7 views
0

javascript를 사용하여 페이지를 인쇄하려고하는데 '인쇄'버튼을 클릭하면 새 창이 팝업 될 때 '잘못된 요청'이 표시됩니다. 여기에 현재 위치를 캡처하고 인쇄 할 미디어 CSS를 할당하여 창을 여는 자바 스크립트 코드가 있습니다.자바 스크립트를 사용하여 페이지를 인쇄하려고 할 때 잘못된 요청이 발생했습니다.

function printerFriendlyNew() { 
    genPopUp = window.open("","printer","toolbar=no,location=no,scrollbars=yes,directories=no,status=yes,menubar=yes,resizable=yes,width=760,height=600"); 
    genPopUp.location.href = document.location.href + "&css=print"; 
    if (genPopUp.opener == null) genPopUp.opener = window; 
    genPopUp.opener.name = "opener"; 
} 

'잘못된 요청'오류가 발생하는 이유는 무엇입니까?

+0

이 내가 URL의 쿼리 문자열이있는이 있기 때문에 ... 미친 나, 그냥 맹목적으로 추가하고 "& CSS = 인쇄"를 해결, 그리고 does'nt하는 사람들을 위해 사람들을 위해 잘 작동 버그 나왔다. 이것을 기존 자바 스크립트에 추가했는데 문제가 해결되었습니다. var contains = document.location.href; if (contains.indexOf ('?') == -1) genPopUp.location.href = contains + "? css = print"; else genPopUp.location.href = contains + "& css = print"; – Ron

답변

0

이 해결책을 얻었습니다 ... 난 미스터리, 나는 단지 맹목적으로 "& css = print"를 추가하고 있습니다. 왜냐하면 저는 쿼리 문자열이있는 URL을 가지고 있기 때문에, 그것들은 정상적으로 동작하지 않습니다. 내 기존 자바 스크립트에 추가하고이 문제를 해결했습니다.

var contain = document.location.href; 
if (contain.indexOf('?') == -1) 
    genPopUp.location.href = contain + "?css=print"; 
else 
    genPopUp.location.href = contain + "&css=print"; 
관련 문제