How to open a new window when clicking a hyperlink?

后端 未结 6 1399
青春惊慌失措
青春惊慌失措 2020-12-18 13:37

I would like to open a new window with height of 600px and width of 200px, after clicking on a hyperlink.

How can I do that in HTML/Javascript?

Do I use some

相关标签:
6条回答
  • 2020-12-18 13:58
    winRef = window.open( URL, name [ , features [, replace ] ] )
    

    source: http://www.javascripter.net/faq/openinga.htm

    0 讨论(0)
  • 2020-12-18 14:08

    JavaScript is the best way of doing this

    var win = window.open(cant remeber this bit); win.resizeTo(w, h); win.focus();

    0 讨论(0)
  • 2020-12-18 14:10

    Creating a New Window with JavaScript (includes window size)
    http://www.fontstuff.com/frontpage/fptut06.htm

    0 讨论(0)
  • 2020-12-18 14:11

    window.open (URL, windowName[, windowFeatures])

    More infos here

    0 讨论(0)
  • 2020-12-18 14:16
    var user_window=window.open('http://www.someplace.com','someplace_window_name','toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,width=1024,height=768');
    user_window.focus();
    

    A user click should initiate this, or it will be blocked by most popup blockers. This works in all browsers I've had to support including IE6+, FF, Opera, Safari.

    The focus bit ensures that the new window is brought to the front.

    As an alternative to a popup window, I'd suggest the Dialog plugin for Jquery.
    That's what I replaced 90% of my popup windows with.
    Your popup becomes a popover (bound within the original window), and this as far as I can tell is never blocked by a popup blocker. The Dialog plugin allows dragable popovers, appearance and disappear effects, and lots of other cool stuff.

    0 讨论(0)
  • 2020-12-18 14:17

    It's far better to attach this to the hyperlink unobtrusively, similar to:

    HTML

    <a href="mypopup.htm" id="popup">This will open in a new window</a>
    

    JavaScript

    window.onload = function() {
        document.getElementById("popup").onclick = function(){
            return !window.open(this.href, "pop", "width=200,height=600");
        }
    }
    

    The benefit of this approach is that you only have to specify the hyperlink in your HTML, and if JavaScript is disabled or produces an error for some reason then it will fallback to just using a standard hyperlink.

    0 讨论(0)
提交回复
热议问题