center window.open on form submit

后端 未结 2 1332
夕颜
夕颜 2021-01-24 09:26

My code looks like this:



        
相关标签:
2条回答
  • 2021-01-24 10:02

    Try this out: http://jsfiddle.net/333Qy/1/

    <script>
      function directions(sacred) {
      var x = screen.width / 2 - 700 / 2;
      var y = screen.height / 2 - 450 / 2;
      console.info(sacred);
      window.open(sacred.action, 'Directions', 'height=485,width=700,left=' + x + ',top=' + y);
      return false;
    }
    </script>
    <p>
      <form action="http://maps.google.com/maps" method="get" target="Directions"
      onsubmit="directions(this);">
        <input class="directions-input" id="saddr" name="saddr" type="text" placeholder="enter zip-code"
        value="enter zip-code" onfocus="this.value = this.value=='enter zip-code'?'':this.value;"
        onblur="this.value = this.value==''?'enter zip-code':this.value;" />
        <input type="submit" class="directions-submit" />
        <input type="hidden" name="daddr" value="210+East+Northampton+Street,+Bath,+PA"
        />
        <input type="hidden" name="hl" value="en" />
      </form>
    </p>
    

    onsubmit should be a function call. Also, sacred is undefined. I have made the changes in the above code

    0 讨论(0)
  • 2021-01-24 10:05
    <form action="http://maps.google.com/maps" method="get" target="Directions"
          onsubmit="Directions=window.open('about:blank','Directions','width=600,height=400,left={left},top={top}'.replace('{left}', screen.width/2-700/2).replace('{top}', screen.height/2-450/2));">..</form>
    

    I don't know why, but i does not always work.
    http://jsfiddle.net/greatghoul/MCRAG/embedded/result/

    Code is here.

    http://jsfiddle.net/greatghoul/MCRAG/

    0 讨论(0)
提交回复
热议问题