Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Redirect if not opened in a popup

  1. #1
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Redirect if not opened in a popup

    Im using the following function to open a pop up:

    Code:
    function popup(){
    var w = window.open('/open.php','Open','width=430,height=550,scrollbars=1');
    w.targetField = targetField;
    w.focus();
    return false;
    }
    But i want to redirect open.php to another page if its not opened in a popup?

    Anyone can help?


    Thnaks.
    Last edited by newbtophp; 01-18-2010 at 01:01 AM.

  2. #2
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    return false;
    you got false when pop up is showed?

  3. #3
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by auriaks View Post
    return false;
    you got false when pop up is showed?


    Not sure, i just do onclick....popup(); on another page; and when i click it opens the open.php in a popup as its supposed too

    Just wanted to block direct file access to open.php (so it has to open in a popup else it would redirect to another page)

  4. #4
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    in what page is your link with onclick?

    maybe you can give me link to your page, to see what you want to do and maybe there is other way...
    Last edited by auriaks; 01-17-2010 at 03:03 PM.

  5. #5
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Its on localhost at the moment, you can test that function anywhere

  6. #6
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    anyone?

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    In javascript you want to know if the window that open.php opens in was opened via javascript and has the name of 'Open' as your code dictates. First of all, this is extremely unlikely if javascript is disabled, right? For that you could just have an actual link for the anchor tag that otherwise would open the popup (something like):

    Code:
    <a href="someother.php" onclick="return popup();">Link Text or Image Tag</a>
    This will take care of folks without javascript enabled, and of folks with javascript who click on the link and use some feature of their browser like "open link" or "open link in a new window", either of which, even with javascript enabled, will either open an empty page, or someother.php.

    Finally, let's say someone has somehow bookmarked open.php or decides to try to navigate there directly for some reason. This javascript in the head of that page will redirect them:

    Code:
    <script type="text/javascript">
    if(!window.opener || window.name !== 'Open'){
    	location.replace('someother.php');
    }
    </script>
    But only if javascript is enabled. It would be invalid, but you could also use a noscript tag to insert a meta tag redirect into the head to take care of non-javascript users, who - however they got there - did not get there via your javascript code.

    PHP itself may have an equivalent to this last bit, if so it would be preferable.
    Last edited by jscheuer1; 01-17-2010 at 08:33 PM. Reason: correct syntax
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP would be able to redirect, but only as a header sent before any code, so there would be no way for it to interact with the javascript to check about the window (and PHP would have no information about the window's status). Javascript or a meta redirect would be the only options (unless there's something else, unrelated, that I'm not thinking of).

    You could also try the same approach but in reverse:
    If it WAS opened by Javascript redirect to the real page. This would eliminate any need for the complex code.
    But you would still need something on that page in case Javascript was disabled, so for that I suggest keeping the code above to send them back. It might be simpler just to use the method above, so consider both approaches.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    if you want to save information or something else, you can hide a link with php, so noone who wasnt supposed to see it will not see it ...
    also, there is a way to manage this link appearance when someone have to paid for the file from link... if user is registered, you can save authentic generated code to his account and then after checking it on the page - link will appear.

    All in all, maybe its hard to understand what im talking about, but i could explain it better if you need something of this kind.

  10. #10
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    cheers resolved

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
  •