Javascript子窗口保持最佳状态

时间:2013-03-05 13:47:42

标签: php javascript focus

我搜索了这个论坛,我找到了一些关于我的问题的主题,但我不是程序员,我无法使用我在这里找到的任何解决方案,因为我的代码与其他用户提供的解决方案不同。

请大家,我有以下问题,我运行的房地产网站仍然在joomla 1.5(已经在迁移到2.5,这对我的系统很痛苦),当用户点击“联系我们“在一个属性详细信息页面内链接,一个javascript窗口打开,其中包含一个简短的表单,用于收集用户关于他在我们的房地产网站上查看的财产的问题。

问题在于,一个用户没有完成填写表单并在父窗口中单击返回,将JS子窗口隐藏在页面底部是很常见的。

当发生这种情况时,如果用户再次点击另一个属性页面中的“联系我们”链接(或者如果忘记他已经打开了联系窗口,则甚至在同一页面中),子窗口仍被父页面隐藏所以我正在寻找一种方法来修改我的系统打开这个子窗口的方式,并放置一些代码使子窗口保持在页面顶部。

另一个解决方案是禁用父窗口,直到用户关闭子窗口或提交子窗口窗体。我试图解决这个问题puttin一个超时自动关闭窗口,但不幸的是,这并没有解决主要问题,这是一个事实,子窗口需要保持在顶部,直到它关闭,直到表单已提交。如果您需要删除超时功能以使子窗口保持在最顶层,这样就可以了,我们可以在必要时删除超时。

为了帮助每个人,我会在此处粘贴调用子窗口的代码,然后是子窗口的代码,这些代码位于不同的.php文件中:

这是我的系统调用子窗口的方式:

<br>
  <b>
    <font size="3">
      <a style="color: #bd0000" href="javascript:void(0)" onclick="window.open('<?php echo $rutaC ; ?>','win2','<?php echo $statusC; ?>');" title="<?php echo JText::_('CONTACT US!'); ?>"><?php echo JText::_('CONTACT US!'); ?>
      </a>
    </font>
  </b>
<br />

这是子窗口的php文件的代码:

<?php defined('_JEXEC') or die('Restricted access');
   JHTML::_('behavior.tooltip');
   JHTML::_('behavior.formvalidation');
   $user =& JFactory::getUser();
   $document =& JFactory::getDocument();
   $component = JComponentHelper::getComponent( 'com_formacion' );
   $params = new JParameter( $component->params );

   $u =& JFactory::getURI();
   //echo $u->getHost();
   $title = JText::_('CONTACT FORM').' '.$this->ThisMenu->name;   
   $document->setTitle( $title );
   $document->setDescription( $title );
   $document->setMetadata('keywords',$title);
   $contact_send = JRequest::getVar('contact_send', 0, '', 'int');

   if($contact_send == 1){
?>

<div style="width:100%; background:#E6E6C6; text-align:center;">
<div>
<br /><br />
<p style="font-size:18px;">
<?php echo ' '.JRequest::getVar('msg');?>
 </p>
<br /><br />
<?php
if(JRequest::getVar('popup')==1){
?>
<a href="#" onclick="window.close()"><?php echo JText::_('Close Window'); ?></a><br /><br />
<script type="text/javascript">window.setTimeout(function(){ window.close(); } , 4000); </script>
<?php
}
?>
</div>
</div>
<?php
}else{
?>

<script type="text/javascript">
function ValidateCaptcha(a,b,c){
var progressvc = $('progressvc');
new Ajax("<?php echo JURI::base();?>index.php?option=com_properties&controller=ajaxCaptcha&format=raw&task=ValidateCaptcha",
{method: 'get',
onRequest: function(){progressvc.setStyle('visibility', 'visible');},
onComplete: function(){progressvc.setStyle('visibility', 'hidden');},
update: $('ValidateCaptcha'),
data: 'captchacode='+a+'&captchasuffix='+b+'&captchasessionid='+c}).request();
            }   
</script>

<style type="text/css">
<!--
.invalid {
font-weight:bold;
color: red;
}
-->
</style>


<div style="padding:10px;" >

<script type="text/javascript">window.setTimeout(function(){ window.close(); } , 603000); </script>


<form action="<?php echo JRoute::_( 'index.php' ); ?>" method="post" id="josForm2" name="josForm2" class="form-validate">
<input type="hidden" name="popup" value="" />

<div class="componentheading"></div>

<table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">
    <tr>
        <td width="100%" colspan="2">
<?php
if($this->ThisMenu->text){
echo $this->ThisMenu->text;
}
?>   
        </td>
    </tr>
</table>

<table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">

     <tr class="header" align="left" valign="bottom">
        <img src="components/com_properties/includes/mail/contact/header-bg.jpg" alt="MYSITE" width="400" height="75" />
    </tr>

    <script>
    var interval;
    var minutes = 10;
    var seconds = 0;
    window.onload = function() {
        countdown('countdown');
    }

    function countdown(element) {
        interval = setInterval(function() {
            var el = document.getElementById(element);
            if(seconds == 0) {
                if(minutes == 0) {
                    el.innerHTML = "countdown terminado!";                   
                    clearInterval(interval);
                    return;
                } else {
                    minutes--;
                    seconds = 60;
                }
            }
            if(minutes > 0) {
                var minute_text = minutes + (minutes > 1 ? ' minutos' : ' minuto');
            } else {
                var minute_text = '';
            }
            var second_text = seconds > 1 ? 'segundos' : 'segundo';
            el.innerHTML = minute_text + ' ' + seconds + ' ' + second_text + '.';
            seconds--;
        }, 1000);
    }
    </script>





    <tr>
        <td width="30%" height="40">
        <b><label id="namemsg" for="name"><?php echo JText::_( 'NAME' ); ?>: </label></b>
        </td>
          <td><input type="text" name="name" id="name" size="40" value="<?php echo $user->name;?>" maxlength="50" /></td>
    </tr>


    <tr>
        <td height="40">
        <b><label id="emailmsg" for="email"><?php echo JText::_( 'EMAIL' ); ?>: </label></b>
        </td>
        <td><input type="text" id="email" name="email" size="40" value="<?php echo $user->email;?>" maxlength="100" /></td>
    </tr>


    <tr>
        <td width="30%" height="40">
        <b><label id="namemsg" for="phone"><?php echo JText::_( 'PHONE' ); ?>: </label></b>
        </td>
          <td><input type="text" name="phone" id="phone" size="40" value="<?php //echo $this->user->get( 'name' );?>" maxlength="50" /></td>
    </tr>


    <tr>
        <td height="40">
        <b><label id="textmsg" for="text">
            <?php echo JText::_( 'MESSAGE' ); ?>:
        </label></b>
        </td>
        <td>
        <textarea name="text" id="text"cols="40" rows="7"></textarea>
        </td>
    </tr>
    <tr>
        <td colspan="2" height="40">
        <input type="checkbox" name="email_copy" id="contact_email_copy" value="1"  />

                <label for="contact_email_copy">
                    <?php echo JText::_( 'send a copy to myself' ); ?>
                </label>
        </td>
    </tr>   
<tr>
    <td colspan="2">

<?php $dispatcher = &JDispatcher::getInstance();
            //JPluginHelper::importPlugin('system');
            $results = $dispatcher->trigger( 'onCaptchaRequired', array( 'user.contact' ) );
            if ($results[0]){?>       
<table>
<tr><td align="center" colspan="2">
<span><?php echo JText::_( 'CAPTCHACODE_FORM_TITLE' ) ?></span>   
</td>
<td colspan="2"></td>
</tr>
<tr>
<?php    

                $dispatcher->trigger( 'onCaptchaView', array( 'user.contact', 0, '', '' ) );
?>
<td width="20px">
<div id="ValidateCaptcha" style="float:left;"></div>
</td>
<td>
<div style="float:right">     
<a style="cursor:pointer;" onclick="ValidateCaptcha(document.getElementById('captchacode1').value,document.getElementById('captchasuffix').value,document.getElementById('captchasessionid').value)"><?php echo JText::_('Test Code'); ?></a>
</div>
</td>
</tr>
<tr>
    <td colspan="3"><div id="progressvc" style="float:left;"></div> </td>
  </tr>
</table>   
<?php } ?>
</td>
</tr>        
</table>
<div align="center" style="margin-bottom:20px;">

    <button class="button validate" type="submit"><?php echo JText::_('Send'); ?></button>

    </div>

    <tr valign="top">


       <td height="20" class="texto"><font size="3">This window will be closed in </font></td>
          <td class="texto"><font size="3"><br/><br/><div id='countdown'></div> <br/>Click here before the time runs out.</td><br/>
    </tr>

    <input type="hidden" name="option" value="com_xxxxxx" />   
    <input type="hidden" name="controller" value="contact" />
    <input type="hidden" name="task" value="send_contact" />
    <input type="hidden" name="product_id" value="<?php echo JRequest::getVar('id');?>" />   
    <?php echo JHTML::_( 'form.token' ); ?>
    </form>


<?php if(JText::_('FIELDAREREQUIRED')!='FIELDAREREQUIRED'){echo JText::_('FIELDAREREQUIRED');} ?>
<?php if(JText::_('SENDMAILTO')!='SENDMAILTO'){echo JText::_('SENDMAILTO');} ?>

<?php if(JText::_('OURPHONE')!='OURPHONE'){echo JText::_('OURPHONE');} ?>


</div>

<?php } ?>

0 个答案:

没有答案
相关问题