1

I'd like to open a popup window, but without given a link : just open it with some HTML and Javascript code (that I pass trought the function).

Tried with :

window.open($('.my_html').html(), "Booking", "width=950,height=680");

How can I do it?

2
  • 2
    Have you tried anything or would you like us to do your work for you? Commented Oct 26, 2011 at 8:02
  • Yeah of course. Added an example... Commented Oct 26, 2011 at 8:03

4 Answers 4

2
writeConsole('Hello from JavaScript!');
function writeConsole(content) {
 top.consoleRef=window.open('','myconsole','width=350,height=250');
 top.consoleRef.document.write(content)
 top.consoleRef.document.close()
}

Source

Sign up to request clarification or add additional context in comments.

2 Comments

It seems to work. But how can I include also the css attribute? :)
Ok done. I resolve it including the <head></head> element with the reference of the css (it will load it dinamically). It's nice :)
2

You can do it like this:

var popup = window.open(#mySettings#);

and then

popup.document.write('#myHTML#');

2 Comments

yeah, but what will be #mySettings#? In fact it gets a uri, not an "html source"
Just leave it (the URI) blank.
2
function openpopup(content){ 
    winpops=window.open('',"test","fullscreen=no,toolbar=yes,status=yes, " +
    "menubar=yes,scrollbars=yes,resizable=yes,directories=yes,location=yes, " +
    "width=500,height=400,left=100,top=100,screenX=100,screenY=100");
    winpops.document.write(content);
} 
openpopup('<h1>This is some test content</h1>');

You can call function on any event, and supply content you want to show.

2 Comments

He says he doesn't want to show a URL. He wants to write custom code to that window.
I have corrected it. At first I thought he doesn`t want to open it on a link click.
1

do you have to use browser popups? They're annoying and can be blocked by ad-blockers.

Why not do it as modal windows instead? like this: http://www.sohtanaka.com/web-design/inline-modal-window-w-css-and-jquery/

or the jQuery plugin jqModal.

3 Comments

in fact what I need is to print that "popup" (later), so I think windows.print will fail with your method...
you can add a print style or styleshhet along with the modal to hide everything except the modal.
will be ok for a simple site, not with tons of elements :) I'm ok with popup, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.