onpropertychange event is not fired when you change document location

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alhalayqa
    New Member
    • Mar 2008
    • 11

    onpropertychange event is not fired when you change document location

    Hello ,

    I have attached the onpropertychang e event to my document as :



    [CODE=javascript]// the handler function

    function propertychangeH andler(){

    alert('property change event...');

    }

    document.onprop ertychange=prop ertychangeHandl er;


    // now, when I change the document.locati on as :

    document.locati on="http://www.google.com" ;
    [/CODE]

    the event is not fired, it doesn' t call the handler .
    I read the documentation of msdn that this event is applied to document object .


    I have IE7 on Window Vista on my machine .


    any suggestion ?

    thanks ,
    Last edited by gits; Mar 11 '08, 02:28 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If you're trying to detect when the page changes, just use onbeforeunload instead.

    Comment

    • mrhoo
      Contributor
      • Jun 2006
      • 428

      #3
      document.locati on is a read only string, now deprecated in favor of document.URL

      You can't change the url of a document with javascript- only the url that is loaded in window.location, which is apparently what IE is doing.

      Comment

      • alhalayqa
        New Member
        • Mar 2008
        • 11

        #4
        Originally posted by acoder
        If you're trying to detect when the page changes, just use onbeforeunload instead.
        Ok , but do you think I can catch what the url being assinged to document.locati on inside the onbeforeunload handler ?

        if you look at my example , document.locati on = "http://www.google.com" .
        could I know that my document will be overwritten by http://www.google.com ?

        thanks .

        Comment

        • alhalayqa
          New Member
          • Mar 2008
          • 11

          #5
          Originally posted by mrhoo
          document.locati on is a read only string, now deprecated in favor of document.URL

          You can't change the url of a document with javascript- only the url that is loaded in window.location, which is apparently what IE is doing.
          if I understood you, simply in javascript you can say :
          document.locati on = "http://example.com".

          this is an assigment, so document.locati on is read/write property !!

          in any case, and same for the window.location = "http://www.example.com ".
          why the onpropertychang e event is not fired !!

          could you please explain more .

          thanks .

          Comment

          • mrhoo
            Contributor
            • Jun 2006
            • 428

            #6
            document.locati on is no longer a property of the document.URL, but an alias for the window's location object.

            When you write to it, you are not changing the url of the document-
            you are changing the window location to the url of another document .

            Comment

            • alhalayqa
              New Member
              • Mar 2008
              • 11

              #7
              Originally posted by mrhoo
              document.locati on is no longer a property of the document.URL, but an alias for the window's location object.

              When you write to it, you are not changing the url of the document-
              you are changing the window location to the url of another document .
              ya, that's clear , thanks very much .

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by alhalayqa
                Ok , but do you think I can catch what the url being assinged to document.locati on inside the onbeforeunload handler ?

                if you look at my example , document.locati on = "http://www.google.com" .
                could I know that my document will be overwritten by http://www.google.com ?

                thanks .
                That would be window.location .href. I'm not sure if you can, but I doubt it. Why do you need to know what the URL of the next page is?

                Comment

                Working...