<a href="" onClick="..."> problem
Hi, very nice to JS and totally new to this forum, so please keep it simple if you can.
I've read that you can make a link with nothing in the URL inorder to use the onClick event handler. Essentially, what I'd like to do is open a new window with my specifications, rather than directly link to the page. What I've tried is this:
Where OpenNewWindow() is the function that does the work. The new window opens just fine, so I'm not concerned that much about the function, as about the statement I posted.
<a href="" onClick="OpenNewWindow()">Click here to open a new window</a>
I find that whenver I do something like this, the browser (IE, generally) takes the <a href=""> to be a link to the home directory. For example, if I'm working locally, when I click on the link the new window will open, but the main window will jump to the index of the directory. Similiarly, if I'm working on my site, the main window will jump to /index.html. This is all very annoying and I haven't found a solution to it.
<a href="#" onClick="window.open();">Click here to open a new window</a>
Thanks a lot, it worked like a charm. I suppose I should assign a tag to that spot on the page, though, because it jumps to the top, which is not what I'd like to happen.
<a href="#" onClick="window.open();return false;">Click here to open a new window</a>
to make sure that the current page isn't reloaded when the new window opens.
I didn't see that at first, but thanks for that little "return false" hint! I was dealing with problem by creating a <a name="...."> to get the referring page to at least be in the correct place after the link was clicked. This fixes that issue. Great!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)