A
A
Andrew2014-08-15 11:01:38
JavaScript
Andrew, 2014-08-15 11:01:38

Could not load the source for javascript error in firefox when opening a popup, what's the problem?

There is a functionality that allows you to click on a link to open a PDF file in a new window and print it out. In chrome, everything works fine, unlike firefox.
Code and usage:

var popupURL = "";
function ShowPopup() {
    var popup = window.open(popupURL, null, 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, width=600, height=800');
    popup.focus();
    popup.print();
}

<a href="javascript: popupURL='{% url "exchange" obj.pk %}?pdf=1'; ShowPopup();" title="{% trans "pdf" %}">pdf</a>

The error appears after executing window.open , error text:
Error loading source:
Could not load the source for javascript:%20popupURL='/exchange/234?pdf=1';%20ShowPopup();.
[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIChannel.asyncOpen]"

How it all looks in the browser:
1. A new empty window with the loader opens.
2. The print window opens. If you try to print, there will be an empty sheet.
3. If you close the print window, the content in the first window is loaded.
What could be the cause of this problem and are there any other methods of sending to print?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Petrov, 2014-08-15
@aphex

When everyone understands that javascript in links is bad, bad, bad.
That opening new windows when it's not needed is bad, bad, bad.
What to write onclick is...
In addition, the PDF will be opened by a plug-in built into the browser, which (incredibly!) has the functions of save, scale, print, and a couple more. Why do they need to be duplicated?

<a href="и_тут_реальная_ссылка_на_pdf" rel="alternate" type="application/pdf">pdf</a>

S
Sergey Romanov, 2014-08-15
@Serhioromano

Remove space after javascript:
HTML
JS

function ShowPopup(url) {
    var popup = window.open('/exchange/' + url + '?pdf=1', null, 'toolbar=0, 
         location=0, directories=0, status=0, menubar=0, scrollbars=0, 
         resizable=0, width=600, height=800');
    popup.focus();
    popup.onload = function(){
        popup.print();
    } 
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question