0

It seems like a lot and its driving me crazy. I need to copy the current URL into the code, which is into the first link. My goal is to as soon as I have this link clicked that it could reload the main page without refreshing it, I guess it would have to be done in ajax/jquery and open a new window with the second link. It is one link doing two things at once. Any help on how all this could be accomplished?

I have this, but of course it is not working.

<a href="window.location.href" onclick="window.open('theotherpage.pl?name=name&zip=123'); return true;">test</a>

Thanks for looking!

Andre
  • 819
  • 3
  • 15
  • 30
  • Not sure what you are looking for... do you want to do two things with one click: 1. Open new tab with new Url and 2. Reload the current Page? – Ziv Weissman May 07 '15 at 17:48
  • Yes! But I need also to copy the current location into the first href, as you can see I am trying to use "window.location.href", but I don't think this is the right way. – Andre May 07 '15 at 17:52
  • Ok, see my solution, if its not exactly what you want, we can work it out – Ziv Weissman May 07 '15 at 22:17

2 Answers2

0

If you're wanting to re-load the page and open a new window, your best bet is to wrap it up in a single function.

The first thing you'd do is something like this:

window.open('theotherpage.pl?name=name&zip=123');

And then redirect using something like this:

window.location.replace("http://full.url.of.this.page/");

A sample of this can be found with this jFiddle.

brazilianldsjaguar
  • 1,409
  • 1
  • 20
  • 45
0

This will accomplish what you seek- open a new tab and reload the current url.

html:

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <input type="text" />
    <a href="www.google.com" target="_blank" onclick="location.reload();">click me</a>
</body>
</html>

I'm not sure why you want to save current url (and where you want to store it), do you want to use it in your "target" url? It can be done via url parameters.

Ziv Weissman
  • 4,400
  • 3
  • 28
  • 61