Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question need help with basic javascript programming

    Hi so i am using onClick="myPopup(); on a button and when someone clicks on the button, it pops up an advertisement in a new tab.

    But is there a way to make the users stay on the page where the button is located instead of forcing the browser to automatically switch to the advertisement tab when a button is clicked?

  • #2
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    onclick="window.location.href='someurl.com'"
    "Yeah science!"
    Online Science Tools

  • #3
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djh101 View Post
    onclick="window.location.href='someurl.com'"
    Thanks for the reply but it didn't work D: I tried with your code but my page redirects to the advertisement.

    You know how when you middleclick a link, the page of the link displays in a new tab but you still stay in the same page where the link is? I want this to happen when a user clicks with a left mouse button.

    1.User clicks on the button
    2.The advertisement shows on another tab
    3.User still stays on the same page

  • #4
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    onclick="window.open('someurl.com','_blank')";

    This will open the url in either a new tab or a new window. There is nothing you can do to determine whether the page opens in a new tab or new window, though, that depends on the browser and the user's settings.
    "Yeah science!"
    Online Science Tools

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Which of the three places web pages open is completely under the browser's owner's control. You can only suggest where it should open in your code and the browser can be set to ignore your suggestion and open it where the browser owner wants it to open.

    For example I have my browser configured so that all pages on the same site open in the same tab replacing one another and all pages from a new site open a new tab - regardless of how the web page is coded.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •