SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    opening link in a new window using JS while keeping html link

    Hi,

    i'd like to create a link that pops up a page in a new windows using JS, and in case JS in not available load that page in the same browser window.

    Here is the code i wrote:

    <a href="target.html" onclick="MyWindow=window.open('target.html','','toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=600'); return false;">

    In Firefox it does just what i meant for it to do. But in IE it just loads the page in the same window.

    any idea why? (except for the obvious that IE s*cks.. )

  2. #2
    Smart programmer silver trophy M.Zeb Khan's Avatar
    Join Date
    Jan 2004
    Location
    Luton, Beds
    Posts
    1,791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi ballboy,

    I just tested that in both IE and Firefox, it works perfectly. In both browsers the popup actually opened. I would say you have javascript disabled in internet explorer.

    Good luck

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Works for me in both Firefox 2 and IE 7, though I'd change it to be more like the following

    Code html4strict:
    <a id="targetPopup" href="target.html">Popup Link</a>

    Code javascript:
    document.getElementById('targetPopup').onclick = function () {
    	popup(this, 'myWindow');
    	return false;
    }
    function popup(el, ref) {
        window[ref]=window.open(el.href,'','toolbar=no,location=no, directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,heig ht=600');
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •