SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using window.open in safari

    Normally window.open will open a new window in firefox, chrome and IE. However, when I use this function in safari the link opens up in the same window meaning that the current page is lost. How can I fix this?

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,191
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try this

    Code JavaScript:
    window.open('http://www.google.com', '_blank');

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,820
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Where window.open opens the new page is under your visitor's control. many people have it set to open a new tab in whichever browser they are using and some people have it set to always just replace the current page. You have no control over anything outside of the current web page if your visitor decides to restrict your access and with some browsers they can even override the JavaScript that you have within the page.

    If it is happening in your own browser and you want it to behave differently to how it is then you need to check what browser settings that you have set up that relate to JavaScript operation. There may also be plugins/extensions in the browser that can affect the behaviour.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the suggestions. I figured out the problem. My window.open was on a link and I thought e.preventDefault would prevent use of the normal link but I had to use return false instead.


Bookmarks

Posting Permissions

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