tags:

views:

193

answers:

2

When a user clicks on a link, I need to update a field in a database and then open the requested link in a new window. The update is no problem, but I don't know how to open a new window without requiring them to click on another hyperlink.

<body onLoad="document.getElementById('redirect').click">
<a href="http://www.mydomain.com?ReportID=1" id="redirect" target="_blank">Report</a>
</body>
+5  A: 
<script type='text/javascript'>
window.open('http://www.mydomain.com?ReportID=1');
</script>
ChristopheD
Can I use target="_blank" with window.open?
cf_PhillipSenn
`window.open` does what `target="_blank"` does - it opens the URL in a new window.
ceejayoz
yes. the second argument to window.open() is the "name" you want to give the window, similar to setting a target on a link.https://developer.mozilla.org/En/DOM:window.open
ob
Oh, I see. window.open is blocked by Firefox pop-up blocker, but target="_blank" isn't.Should I just ask the client to enable popups from their own website?
cf_PhillipSenn
+1  A: 

You can extract the href from the a tag:

window.open(document.getElementById('redirect').href);
treznik
Does window.open work with target="_blank"?
cf_PhillipSenn
ceejayoz answered your question, yes.
treznik