4

Let's say i have this code

<p id="test">
  some content
<p>
<a href="#" id="test-link">Open</a>

Now i want -using javascript/jquery- to create a popup window, the window content is the content of test paragraph, when test-link is clicked. How could this be done?

4 Answers 4

10
  <a href="javascript:popup();"  id="test-link">Open</a>

function popup()
{
  var generator=window.open('','name','height=400,width=500');

  generator.document.write('<html><head><title>Popup</title>');
  generator.document.write($("#test").html());
  generator.document.write('</body></html>');
  generator.document.close();
}
Sign up to request clarification or add additional context in comments.

Comments

3

You can do this using jQuery UI (dialog) (see examples in the reference documentation).

2 Comments

Unfortunately, I want a popup window, not a modal or dialog.
In this case, the answer by pranay_stacker should work. I tend to prefer dialogs, since they you can get more control regarding their position and they tend to look better. Some people force popups to open in new tabs and/or prevent them from resizing, since these can be annoying depending on the site, especially auto-opening (onload) popups, although few modern websites seem to use those nowadays.
1

im using http://defunkt.github.com/facebox/ its nice.

Comments

0

Use jQuery UI dialog to show popup.

For your html:

$(function()
{
    $("#test-link").click(function()
    {
         $("#test").dialog({ resizable: true,
                modal: false, draggable: true
         });
    });
});

If you don't want to go for jQuery UI dialog then you can use ThickBox.

Comments

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.