0

I use a standard bookmarklet that looks something like this:

javascript:(function () {var p = document.title;var uri=document.location;window.location = 'http://localhost:8084/'})()

However, every time I use it, it generates a new tab. How do I stop window.location from opening a new tab, or better, how do I get it to load the page in another tab if it exists (ie, if localhost is already open, that's the tab that will be used.)

jpsimons
  • 27,382
  • 3
  • 35
  • 45
metalaureate
  • 7,572
  • 9
  • 54
  • 93

1 Answers1

1

This question looks similar to

open url in new tab or reuse existing one whenever possible

window.open(URL,name,specs,replace)

URL : Optional. Specifies the URL of the page to open. If no URL is specified, a new window with about:blank is opened

name : Optional. Specifies the target attribute or the name of the window. The following values are supported:

  • _blank - URL is loaded into a new window. This is default
  • _parent - URL is loaded into the parent frame
  • _self - URL replaces the current page
  • _top - URL replaces any framesets that may be loaded
  • name - The name of the window (Note: the name does not specify the title of the new window)

     < script >
      document.getElementById("container").onclick = function(evt) {
        if (evt.target.tagName === "A")
          window.open(evt.target.href, evt.target.href);

        return false;
      } < /script>
<div id="container">
  <a href="https://www.google.com">goo</a>
  <a href="https://www.stackoverflow.com">sta</a>
</div>
Community
  • 1
  • 1
vijay
  • 10,276
  • 11
  • 64
  • 79
  • How do you get a reference to the window name of a page that was not loaded programmatically? I.e., if my web app is at www.abc.com, but i am looking at www.def.com, how do I get my bookmarklet to open in www.abc.com's tab? – metalaureate Jan 11 '15 at 15:11
  • 1:Can you express more what are you trying to create with the help of [jsfiddle](http://www.jsfiddle.net) or [plnkr](http://www.plnkr.co) with html + javascript + scenario explanation 2:You have created self firing function that will fire on page load ,so are you sure you don't want on click3:Please go throught [Window.name what it means](http://www.w3schools.com/jsref/prop_win_name.asp) And [Get_window_name_specified](http://www.java2s.com/Tutorials/Javascript/Browser/Window/Get_window_name_specified_when_new_windows_are_created_using_the_Window_open_method_in_JavaScript.htm) – vijay Jan 11 '15 at 17:37