views:

33

answers:

5

Hey All,

I have this problem where when I have this html in firefox it opens a new window

<a style="float:right;" href='javascript:window.location.href="#";'onClick="javascript:addNewRecord();">New Record</a>

I have tried self.location, window.location, #body, and #h1 as the href.

Originally I had the code as, but in firefox that did not do anything but open a fresh window, and not perform my function. The code works perfect in chrome.

<a style="float:right;" href="javascript:addNewRecord();">New Record</a>
A: 

Try this

<a onclick="javascript:addNewRecord();">New Record</a> 
Yves M.
A: 

How your code behaves depends entirely on what the addNewRecord() function does (including what it returns).

Without seeing inside that function it's hard to tell, but I'd say that what is happening is inside there.

Note that what you put in the href="" part probably is not affecting the behaviour you're seeing.

thomasrutter
A: 

Try this:

<a href="#" onclick="addNewRecord();" style="float:right">New Record</a>

You don't want your link returning it's default function, so return false instead. add return false; as the last line of your addNewRecord() function.

JKirchartz
+1  A: 

try :

onClick="addNewRecord();return false"
Joe
A: 

Joe had it right

The canonical way is

<a style="float:right;" href="#"
onClick="addNewRecord(); return false">New Record</a>

or better:

<a style="float:right;" href="#"
onClick="return addNewRecord()">New Record</a>

where addNewRecord returns false at the end of the function

mplungjan