Reputation: 1413
the following is on a page, when i click it - I DO NOT want the page to refresh, but only the new window which this link opens - i want to refresh that newly opened page, not the main window.
clicking the link opens the new window correctly, but refreshes the main window also (where the link lies). that is undesirable and i want to know how to stop it from doing so.
<a href="" onclick="window.open('URL','mywin');mywin.location.reload();">clik to open new window</a>
<a href="" onclick="window.open('URL','mywin');">clik to open new window</a>
pl advice.
as advised below, but not working: infact it is breaking the new window, new window appears as blank window!
<a href="" onclick="mywin = window.open('URL','mywin');mywin.location.reload();">clik to open new window</a>
Upvotes: 0
Views: 2498
Reputation: 1413
friends, it is resolved by doing this:
<a href="#" onclick="window.open('URL','mywin');">clik to open new window</a>
Upvotes: 0
Reputation: 7134
The problem with the main window reloading is likely the href=""
line. This could be causing the browser to navigate to the same page where it is presently (and therefore refreshing). You should add return false;
to the js, and likely also adopt a more standard link target like href="#"
which will navigate to the top of the same page without a refresh (though this will still get cancelled by the false
return).
Upvotes: 0
Reputation: 436
Here's the proper way to open a link in a new window. If javascript isn't available, the link will still work.
<a href="http://URL" onclick="window.open(this.href,'popupwindow');return false;">Click Me</a>
Upvotes: 3
Reputation: 888167
mywin
is a window name, not a variable.
You need to store the returned wobject from window.open()
in a global variable:
onclick="window.mywin = window.open('URL','mywin');">
Upvotes: 0