We help IT Professionals succeed at work.

Hook url exists and ...

Indefrei
Indefrei asked
on
Hi,

I try to find out, if a ref adress exists or not
before showing this site
if not i want to give an error and go back to the opener

How can i do this ?

Indi
Comment
Watch Question

If you own the 'test' page, you can use the onload event handler to send a message back to the opener to say 'Yes I exist'.
However, I suspect you want to test pages outside your own site and, unfortunately, JavaScript has built in protection to stop programmers accessing information from external pages.

If you are talking about testing pages that you own, I can give you the JavaScript code to do this.
Otherwise, JavaScript can't help - I suggest you try re-posting this question in another topic (e.g. Web Developers).

Author

Commented:
Hi,

i just want to replace
the Browsers standard error in case it can't open a site
with my own error message

Indi
From what you're saying it sounds as though you are talking about an external site - in which case JavaScript cannot help you for the reasons stated in my previous comment.
Try posting this question to the Web Developers board. Search engines have the capability to check if a server is up and running, so the technology you require does exist.

Best of luck
Steve

Author

Commented:
Hi, Steve

guess, i have to accept this

but try to translate the following for Netscape, please
(cause in NS it opens the site every time,
although there is not an opener site,
means i only put the url into the browsers adressbar
and then the site should NOT be opened, but is opened in NS)

in IE it works well

it asks if there is an opener site and
compares the opener URL's filename with an ID (Rufer) in the called site


function checkit()
{

if (opener)
{
     var aufrufer = opener.document.all.Rufer.innerText + ".htm";
     var Pfad = opener.document.URL;
     var Woerter = Pfad.split("\\");
     if (Woerter.length > 1)
     {
          var test = Woerter[Woerter.length - 1];

          if ( test == aufrufer)
              opener.close();
           else
              self.close();
     }
     else
          document.write("URL SplittingError : SplitCount : " + Woerter.length);

}

else
document.write("Sorry, NO ACCESS !");
}

anyway, pts will be yours,

thanks
Indi

Author

Commented:
Oops
compares the opener URL's filename with an ID (Rufer) in the called site

should be

the calling site

Hi,

not sure how you are experiencing differences between NS and IE, when I place the script into a page and load it both IE (v5.0) and NS (v4.7) display the 'No Access' message and then display the content of the page.

I assume that what you really want is to refuse the user access to the page's content.
In which case, try the following modified version.
Instead of writing a 'No Access' message into the page it displays an alert box and forwards the user to an error page. You will obviously have to decide on what the error page ("http://www.mysite.com/errorpage.html") should be (blank page or simple error message), but it will stop user's seeing your content.
Note the document.replace method - this prevents the URL of your page appearing in the user's browser history. As far as the user is concerned they were directed straight to your error page.

Regards,
Steve

<script>

function checkit()
{
  if (opener)
  {
    var aufrufer = opener.document.all.Rufer.innerText + ".htm";
    var Pfad = opener.document.URL;
    var Woerter = Pfad.split("\\");

    if (Woerter.length > 1)
    {
      var test = Woerter[Woerter.length - 1];

     if ( test == aufrufer)
       opener.close();
     else
       self.close();
    }
    else
      document.write("URL SplittingError : SplitCount : " + Woerter.length);

  }
  else
  {
    alert("Sorry, NO ACCESS !");
    document.location.replace( "http://www.mysite.com/errorpage.html" );
  }
}

checkit();

</script>

Author

Commented:
Steve,
differences as i described above
perhaps cause i use the german versions of IE 5.0 and NS 4.6 AND 6.0
but anyway
thanks a lot for your help
and cu again in other qs
H a n d
Indi

Author

Commented:
keep on running, Steve...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.