-1

I am using the code shown in the images below. I have tried many ways like closing login window, before opening a new one. I have also tried many ways like window.open("index.HTML", '_self', false) and window.location.replace("index.HTML") but they are not working at all:

HTML code

JS Code

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Zaid
  • 79
  • 8
  • What happens when you try `window.open("index.html", '_self', false)`? Do you get a new window open? – An0nC0d3r Dec 01 '15 at 22:59
  • it refreshing the same "Login" window and not opening "index.html" – Zaid Dec 01 '15 at 23:03
  • And what if you did `window.open("https://www.google.com", '_self', false)`? Do you see the google site or Login page? If you see Google, you have a path relativity issue. You may wish to try `window.open("/index.html", '_self', false)` or `window.open("../index.html", '_self', false)`... – An0nC0d3r Dec 01 '15 at 23:07
  • Or fully qualify it... `window.open("http://www.yourdomainname.com/index.html", '_self', false)` – An0nC0d3r Dec 01 '15 at 23:09
  • Same results...not opening google.com – Zaid Dec 01 '15 at 23:09
  • 1
    I really don't know how taking a screenshot, cropping it, uploading it and then copy paste that link is easier that just copy pasting the code. – gre_gor Dec 01 '15 at 23:23
  • 1
    Why screenshot? Copy the code, and paste it here. – ataravati Dec 01 '15 at 23:45

2 Answers2

0

I usually use window.open("http://www.example.com", "_blank") Also check your pop-up blocker since it will most probably detect this as popup and block it.

If not then use a monkey patch which is create an html anchor tag with target="_blank". Hide it with CSS visibility: hidden, then invoke the click event using JS.

Read more about popups and blocking in this answer. If your window.open event was not triggered by a click then most probably it would be blocked.

Community
  • 1
  • 1
Oss
  • 4,052
  • 2
  • 18
  • 35
  • He wants to open the window in the same tab To do this, one should not use `window.open(..., "_blank")` because this will open up the page in a new **blank** window – Viraj Shah Dec 01 '15 at 23:55
0

What you want to do, if I am not mistaken, is open a new webpage but using the same window (or tab)... To do this, you should modify the window.location property.

For example:

window.location = "new_page.html"

This will take you to new_page.html.

If your current location is: /users/muhammad/index.html
Then the page will take you to: /users/muhammad/new_page.html

Leave a comment if you have any questions!

=)

Viraj Shah
  • 159
  • 11
  • Exactly ! this is what i want..But the solution you provided is not working..i already tried this one..it's not taking me to new_page..but refreshing the old one. – Zaid Dec 02 '15 at 00:12
  • Try doing this: CTRL + SHIFT + I (that is an uppercase i) – Viraj Shah Dec 02 '15 at 00:16
  • You will be prompted with a console. There type your command: `window.location = ...`, and leave a comment with the output of that command – Viraj Shah Dec 02 '15 at 00:17
  • well on typing window.location = "index.html" on console . it's taking me to the page "index.html" – Zaid Dec 02 '15 at 00:30
  • thats odd behavior... can you upload the code to dropbox, or google drive and comment a link so that I can further inspect the code – Viraj Shah Dec 02 '15 at 00:32
  • I got it...this happens only when i use Input of type="text"....but when i replace it with type ="email" ,it works fine ...i don't know why it's happening – Zaid Dec 05 '15 at 10:39