programing

하위 창에서 인쇄 미리 보기가 열릴 때 Google Chrome이 Ajax 요청을 차단합니다.

starjava 2023. 8. 15. 09:40
반응형

하위 창에서 인쇄 미리 보기가 열릴 때 Google Chrome이 Ajax 요청을 차단합니다.

두 개의 파일이 있습니다.index.html그리고.print.html

첫 번째는 열리는 버튼이 포함되어 있습니다.print.html단순 명령 사용:

window.open("print.html", "_blank", "menubar=yes,toolbar=yes,status,scrollbars,resizable");

print.html에는 인쇄 미리 보기 대화 상자를 여는 단추가 하나만 포함되어 있습니다.

<button onclick="window.print();">

인쇄 미리 보기 대화 상자를 열 때 문제가 나타납니다.이 경우 다음 작업을 수행합니다.index.html즉, Ajax 요청을 시작하는 다른 파일이 일시적으로 차단되어 대기열에 배치됩니다.미리 보기가 닫혀 있는 경우에만 브라우저가 모든 요청을 실행합니다.

구글 크롬(24.0.1312.52m)에서만 볼 수 있습니다.

누가 이것이 크롬의 버그인지 확인할 수 있습니까?

크롬 버그가 있습니다.window.print()DOM에 태그가 있을 때는 작동하지 않습니다.이 기능을 호출하면 해결될 수 있습니다.

function printPage() {
    window.print();

    //workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633
    if (window.stop) {
        location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear
        window.stop(); //immediately stop reloading
    }
    return false;
}

서버가 오리진 헤더를 추가하지 않았습니다..htaccess에 추가해야 합니다.예:

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

또는 print.html의 PHP에 추가할 수 있습니다(html 파일에서 PHP를 사용할 수 있는 경우).

header ("Access-Control-Allow-Origin: *");
header ("Access-Control-Allow-Headers: origin, x-requested-with, content-type");
header ("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");

설치해야 합니다.mod_headersApache에서 설정하고 설정합니다..htaccess

Header add Access-Control-Allow-Origin "*"

저도 Chrome과 비슷한 문제가 있었습니다. 보안 정책 때문에 Chrome은 로컬 파일에 액세스할 수 없습니다.AJAX에 전화를 걸 때 이 오류가 발생합니다.

XMLHttpRequest cannot load file:///*. Origin null is not allowed by Access-Control-Allow-Origin.

내가 알기로는 - 당신은 다음과 같은 매개변수를 가진 크롬을 출시해야 합니다.

--allow-file-access-from-files

도움이 되길 바랍니다.

언급URL : https://stackoverflow.com/questions/14462163/google-chrome-blocks-ajax-requests-when-print-preview-is-opened-on-child-window

반응형