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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    a way to get the phantom urL?

    I am working with a web site where I cannot work on the server side, and there is a link that when clicked goes to a page with a different url than the one clicked. That other url has information in it that I would like to retrieve using ajax - I just want the url, I don't need any of the page content. I have looked all over and can't find any way to do this. Is there a way?

    G

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    I think some clarification is needed. Am I understanding this correctly?

    User clicks link on page 1. That link goes to page 2 then page 2 redirects to page 3. You want page 3's URL?
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes - though I think more likely the user clicks on the link and it gets translated at the server into a different url - so whether that means two pages or 3 pages, I'm not sure.

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    Are pages 1 and 2 (and possibly 3 if there is a 3rd) on the same server?
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by harbingerOTV View Post
    Are pages 1 and 2 (and possibly 3 if there is a 3rd) on the same server?
    Yes, all are on the same server.

  • #6
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    well, I guess you could try this:

    Page1.php
    Code:
    <!DOCTYPE html>
    <html> 
        <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
            <title></title>
    		
        </head>
        <body>
    		<a href="page2.php" class="link">Link to Page2.php</a>
            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js<?php echo $cache; ?>"></script>
    		<script>
    			$('a.link').click(function(e){  
    				e.preventDefault();
    				$('body').append('<iframe hidden />');
    				url = $('.link').attr('href');
    				$.ajax({
    					type: "GET",
    					async: false,
    					url: url,
    					success: function(data) {
    						$('iframe').attr('src' ,url);
    					},
    				    error: function(data) {
    						alert("fail");
    				    }
    				});
    				$("iframe").load(function(){
    					alert($(this).get(0).contentWindow.location.href);
    				});
    			});
    		</script>
        </body>
    </html>
    Page2.php
    Code:
    <?php
    	header("Location: page3.php");
    	die();
    ?>
    Page3.php
    Code:
    HI!:D
    So you click the link, ajax fires appending a hidden iframe to the body. I used HTML5's hidden" but not sure how supported it is. Then on success, change the src of the iframe. When the ifra,e has finished loading, alert the src of it. In this case, "url/page3.php"

    Only tested on Firefox.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    harbingerOTV's solution looks like it would work. But that will prevent the link to work normally. Clicking the link would not load the content of that link on the page as it normally would.

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks - some great insights and code. I don't need (or want at all) the page content, just need the url - but not quite sure I want to be introducing a hidden iframe. Thinking about it a little more.

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried the code below which I found in one of the threads that glenngv kindly linked - firefox allowed it (chrome came up null for baseURI), but returned the original URL as baseURI ... so no luck

    var r = new XMLHttpRequest();
    r.open("GET", "http://domain.com/xxx/yyy.pdf");
    r.overrideMimeType("text/xml");
    r.onload = function()
    {
    alert('hi');
    alert(r.responseXML.baseURI); //gets the URL the request was redirected to!
    }
    r.send(null);


  •  

    Posting Permissions

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