i am creating a hyperlink . i want to that page should open in pop window wat code should i use??

Dani AI

Generated

asked about opening a link in a popup, and recommended JavaScript/jQuery while posted an inline example and noted a browser caveat. Below is a modern, unobtrusive pattern that keeps a working HTML link for no-JS users, opens a sized popup when clicked, and handles common issues (popup blockers, opener security, mobile behavior).

<a href="page.html" class="popup" title="Open page in a new window">Open page</a>

<script>
document.addEventListener('click', function (e) {
  if (!e.target.classList.contains('popup')) return;
  e.preventDefault();
  var url = e.target.href;
  var w = 800, h = 600;
  var left = Math.max(0, (screen.width - w) / 2 | 0);
  var top = Math.max(0, (screen.height - h) / 2 | 0);
  var features = 'width=' + w + ',height=' + h + ',left=' + left + ',top=' + top +
                 ',resizable=yes,scrollbars=yes,menubar=no,toolbar=no,location=no,status=no';
  var win = window.open(url, '_blank', features);
  if (win) try { win.opener = null; } catch (err) { /* best-effort noopener */ }
  else window.open(url, '_blank'); /* fallback if popup blocked */
});

Keep in mind: many mobile browsers ignore sizing and features; popups are often blocked unless opened from a direct user gesture; prefer in-page modals/iframes for better UX when appropriate. Use rel="noopener noreferrer" with target="_blank" when you rely on plain links to avoid window.opener risks. See Window.open (MDN) and the rel attribute notes on MDN for security guidance: rel (MDN).

Recommended Answers

All 2 Replies

javascript or jQuery is good

<a href="javascript:" onclick="window.open('http://www.google.co.uk', 'Google', 'height=500, width=700');">popup window</a>

also for IE, page titles cannot contains spaces

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.