0

I have an anchor tag that works perfectly fine in IE. Here is an example (less some additional parameters I've omitted for clarity)

<a href="javascript:void(0)" onclick="parent.navigate('wizard.aspx?Modal=Yes')">Add</a>

Unfortunately it would appear that parent.navigate does not work in other browsers such as chrome. The error I receive is: Uncaught TypeError: Object [object global] has no method 'navigate'

I've searched online for an alternative cross-browser solution but haven't been able to successfully make anything else work. I've tried window.location, window.location.href but nothing seems to be working.

Any ideas? Thanks!

UPDATE: This anchor tag resides in an iframe (which is also part of wizard.aspx). What the link ultimately does is updates something within the frame. But regardless, all I'm looking for is an alternative to parent.navigate so it will work in other browsers besides IE. And I've already researched window.location and window.location.href found in other stack overflow articles but they obviously don't work hence why I posted a question.

FINAL UPDATE: Working code.

<a href="javascript:void(0)" onclick="parent.location.href='wizard.aspx?Modal=Yes')">Add</a>
  • 1
    possible duplicate of [Should I use window.navigate or document.location in JavaScript?](http://stackoverflow.com/questions/948227/should-i-use-window-navigate-or-document-location-in-javascript) – Naftali Aug 01 '13 at 20:50
  • as stated, this solution didn't work. – univegar304 Aug 01 '13 at 20:53
  • @univegar304 As written, it shouldn't work (in an iframe), since you're operating on `document` or `window` rather than `parent`. Does `parent.location.href="..."` work? – apsillers Aug 01 '13 at 20:55
  • no, it does not. Uncaught TypeError: Property 'href' of object [object Location] is not a function – univegar304 Aug 01 '13 at 20:59
  • 2
    @univegar304 Stop using parenthesis. For `location.href`, you need to use an assignment operator. `parent.location.href = "..."`, not `parent.location.href("...")`. – Jonathan Lonowski Aug 01 '13 at 21:04

2 Answers2

1
window.location.href = 'URL';

is the standard implementation for changing the current window's location.

.navigate does not work in all browsers.

Naftali
  • 144,921
  • 39
  • 244
  • 303
1

Try

<a href="javascript:void(0)" onclick="window.parent.location = 'wizard.aspx?Modal=Yes'">Add</a>
George Bezerra
  • 121
  • 2
  • 9
  • No luck. Uncaught TypeError: Property 'location' of object [object global] is not a function – univegar304 Aug 01 '13 at 20:56
  • 2
    @univegar304 That error seems very weird, considering this code doesn't use `location` as a function. Are you calling `window.parent.location("...")` by mistake (i.e., trying to call it as function instead of setting its value with `=`)? – apsillers Aug 01 '13 at 20:57