SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Forcing links to open in new browser window

    Can someone share Javascript code to force links to open in a new browser window?

    The link will be ad generated by Javascript code.

    Here is a bit more detail about my situation. I am creating a web-based mobile app. In other words, the native app acts just like a set of frames that load web pages. One of the frames loads an ad. The ad is invoked via javascript provided by various mobile ad networks.

    On the iPhone, we are noticing the ad loads within the ad frame inside the app, instead of spawning a new browser window. We would like to resolve this w/ javascript code that forces all links (specifically links generated via javascript) to open in a new browser window.

    Thanks.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,839
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The only way to "force" it is to open it in the same window as an overlay in front of the existing page.

    Your visitors have full control over what opens in a new window, what opens in a new tab and what overwrites the current page.
    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="^$">

  3. #3
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I'm looking for is when the ad/link is clicked... it opens in a new window.

    The click is happening from within the app, not a browser.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,839
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by dtang4 View Post
    The click is happening from within the app,
    So you will need to hard code opening a new window into the non-browser app.
    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="^$">

  5. #5
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    So you will need to hard code opening a new window into the non-browser app.
    Right, my question is what that code would look like.

    The ads are created via Javascript (e.g. like an AdSense ad). I feel like, w/ Javascript, I should be able to create some behavior tied to certain tags and/or actions that will make clicked links resolve in new windows.

    Please let me know if my question is unclear and I can clarify. Thanks.

  6. #6
    SitePoint Addict
    Join Date
    Jan 2002
    Location
    NJ/NY
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's an example to explain my situation...

    Let's say this is the contents of my HTML file:

    Code:
    <script src="http://3rdpartysite.com/ad.js" type="text/javascript"></script>
    Let's say this is the contents of the 3rd-party ad Javascript file:

    Code:
    document.write("<a href=http://advertiser.com><img src=http://3rdpartysite.com/ad.gif border=0></a>");
    Is there Javascript that I can add into my HTML file to add the new window behavior (e.g. target="_blank") to the link being generated by the 3rd-party Javascript file?


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
  •