Search code examples
javascripthtmlfirefoxhyperlinkhref

Firefox link to javascript function opens a new window when not intended


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>

Solution

  • 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.