[beginer]Why this script failed to work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • devdoer

    [beginer]Why this script failed to work?

    HI:

    I paste my script below:

    <html>
    <head>
    <script src="http://code.activestat e.com/js/jquery-1.2.1.js"
    type="text/javascript"></script>

    <script language="javas cript" type="text/javascript">
    function onLoad() {
    var frame1 = $("#frame1");
    alert("1");
    var innerDoc = (frame1.get(0). contentDocument ) ?
    frame1.get(0).c ontentDocument : frame1.get(0).c ontentWindow.do cument;
    alert("2");
    var b=innerDoc.body ;
    alert("3");
    alert(innerDoc. body.scrollHeig ht);
    }
    </script>

    </head>
    <body>
    <iframe id="frame1" src="http://www.baidu.com" width=100%
    onload="onLoad( )">
    </body>
    </html>

    The script only alert "1" in IE and alert "2" in firefox. It seems
    stop execute after then.

    Does any guy know why?
  • webzhao

    #2
    Re: Why this script failed to work?

    On Sep 28, 5:14 pm, devdoer <devdo...@gmail .comwrote:
    HI:
    >
    I paste my script below:
    >
    <html>
        <head>
            <script src="http://code.activestat e.com/js/jquery-1.2.1.js"
    type="text/javascript"></script>
    >
            <script language="javas cript" type="text/javascript">
                function onLoad() {
                    var frame1 = $("#frame1");
                    alert("1");
                    var innerDoc = (frame1.get(0). contentDocument ) ?
    frame1.get(0).c ontentDocument : frame1.get(0).c ontentWindow.do cument;
                    alert("2");
                    var b=innerDoc.body ;
                    alert("3");
                    alert(innerDoc. body.scrollHeig ht);
                }
            </script>
    >
        </head>
        <body>
            <iframe  id="frame1" src="http://www.baidu.com" width=100%
    onload="onLoad( )">
            </body>
        </html>
    >
    The script only alert "1" in IE and alert "2" in firefox. It seems
    stop execute after then.
    >
    Does any guy know why?
    testttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttttttttt ttttttttt

    Comment

    • Stevo

      #3
      Re: [beginer]Why this script failed to work?

      devdoer wrote:
      HI:
      >
      I paste my script below:
      >
      <html>
      <head>
      <script src="http://code.activestat e.com/js/jquery-1.2.1.js"
      type="text/javascript"></script>
      >
      <script language="javas cript" type="text/javascript">
      function onLoad() {
      var frame1 = $("#frame1");
      Why the # character in there? Maybe it's a prototype.js syntax thing, I
      don't know.
      alert("1");
      var innerDoc = (frame1.get(0). contentDocument ) ?
      You're not checking first if frame1 != null, which it would be if that #
      above was wrong. You're also trying to access the contentDocument of a
      page in a different domain. This is actively blocked by the browsers for
      security reasons.
      frame1.get(0).c ontentDocument : frame1.get(0).c ontentWindow.do cument;
      alert("2");
      var b=innerDoc.body ;
      alert("3");
      alert(innerDoc. body.scrollHeig ht);
      }
      </script>
      >
      </head>
      <body>
      <iframe id="frame1" src="http://www.baidu.com" width=100%
      onload="onLoad( )">
      </body>
      </html>
      >
      The script only alert "1" in IE and alert "2" in firefox. It seems
      stop execute after then.
      >
      Does any guy know why?

      Comment

      • devdoer

        #4
        Re: Why this script failed to work?

        On Sep 28, 6:07 pm, Stevo <n...@mail.inva lidwrote:
        devdoer wrote:
        HI:
        >
        I paste my script below:
        >
        <html>
            <head>
                <script src="http://code.activestat e.com/js/jquery-1.2.1.js"
        type="text/javascript"></script>
        >
                <script language="javas cript" type="text/javascript">
                    function onLoad() {
                        var frame1 = $("#frame1");
        >
        Why the # character in there? Maybe it's a prototype.js syntax thing, I
        don't know.
        >
                        alert("1");
                        var innerDoc = (frame1.get(0). contentDocument ) ?
        >
        You're not checking first if frame1 != null, which it would be if that #
        above was wrong. You're also trying to access the contentDocument of a
        page in a different domain. This is actively blocked by the browsers for
        security reasons.
        But by using firebug, I can view the innerDoc 's content and other
        attributes in the debug window.

        Comment

        • RobG

          #5
          Re: Why this script failed to work?

          On Sep 28, 7:14 pm, devdoer <devdo...@gmail .comwrote:
          HI:
          >
          I paste my script below:
          >
          <html>
              <head>
                  <script src="http://code.activestat e.com/js/jquery-1.2.1.js"
          type="text/javascript"></script>
          >
                  <script language="javas cript" type="text/javascript">
                      function onLoad() {
                          var frame1 = $("#frame1");
          That looks like something from jQuery, so ask in a jQuery forum.


          --
          Rob

          Comment

          Working...