-4

Suppose I have two html files: 'page1' and 'page2'

Code in page1:

<html>

<body>
page1
<a href="page2.html" target="_blank"> click to go to page 2</a>
</body>

</html>

Code in page2:

<html>

<body>
page2
<a href="page1.html" target="_blank"> click to go to page 1 </a>
</body>

</html>

Using this I can open page2 using hyperlink in page1 in a new tab in the same window and viceversa

Is it possible to the same thing using javascript

Gajju
  • 423
  • 2
  • 10
  • 22
  • 4
    use `window.open(urlhere)` – Milind Anantwar Apr 02 '14 at 06:54
  • possible duplicate of [How can I make a redirect page in jQuery/JavaScript?](http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript) – Govind Singh Apr 02 '14 at 06:55
  • 1
    use `location.href = "page2.html";` if you want to open a page in the same window. – Derek 朕會功夫 Apr 02 '14 at 06:55
  • I am using a button, I am using 'window.open('page2.html','_newtab');' in it, and I am supposed to open more than 2 new tabs in just one click, but I am unable to do that since only the last tab is opening, its like the last tab is kinda overwriting the previous ones – Gajju Apr 02 '14 at 08:26
  • The OP is asking for a new tab, not the current page nor popup. – Farid Nouri Neshat Apr 10 '14 at 10:26
  • possible duplicate of [Opening new window/tab without using \`window.open\` or \`window.location.href\`](http://stackoverflow.com/questions/11735889/opening-new-window-tab-without-using-window-open-or-window-location-href) – Farid Nouri Neshat Apr 10 '14 at 10:27

3 Answers3

1

lots of way possible ..

1.

<script language="javascript" type="text/javascript">
    window.location.href="login.jsp?backurl="+window.location.href;
</script>

2.

<script language="javascript">
    alert("back");
    window.history.back(-1);
</script>

3.

<script language="javascript">
    window.navigate("top.jsp");
</script>

4.

<script language="JavaScript">
    self.location="top.htm";
</script>

5.

<script language="javascript">
    alert("Access Violation");
    top.location="error.jsp";
</script>

6.

<script language="javascript">
    window.location = window.location.host;
</script>
Govind Singh
  • 15,282
  • 14
  • 72
  • 106
0

check this question here.you can use

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
Community
  • 1
  • 1
Aameer
  • 1,366
  • 1
  • 11
  • 30
0

You can add an click event listener to your link element (or any other) and set the href property in the location object. Let’s use inline onclick for illustration:

<a href="index.html" onclick="location.href='index.html';return false;">Link</a>

By clicking on this element, the onclick handler will be executed, setting the href, i.e. the current address. By returning false, the default action will be prevented (see MouseClick.preventDefault()).

This is kind of a JavaScript surrogate for HTML hypertext behavior. You also can do other cool things with Window.location.

dakab
  • 5,379
  • 9
  • 43
  • 67