.JS表单不适用于Safari

时间:2015-02-20 01:03:13

标签: javascript forms safari

我在iframe中有一个表单,用于向MLS IDX提交信息并显示属性。该表单在Chrome和Mozilla上运行良好,但在使用Safari时,只需在新窗口中重新加载页面,而不是显示结果页面。我从IDX网站复制了.js和表单,对.js一无所知。该页面实际上以远程.js文件为目标,并且在实际页面上也有.js。该页面位于mariaraymer.com/test1.html

感谢任何帮助。 谢谢!

更新2:在Safari中注意到,在提交后快速转到第二页,然后返回原始网址 - 页面的网址为http://mlssearch.topproduceridx.com/system/safari.asp?url=。页面有这个javscript。页面看起来是专门用于safari,因为它不会像chrome或firefox这样的页面。

<script language="JavaScript">
window.setTimeout(function() {
    if (document.cookie.indexOf('test_cookie=1') < 0) {
        var name = 'test_cookie', div = document.getElementById(name), iframe = document.createElement('iframe'), form = document.createElement('form');
        iframe.name = name;
        iframe.src = 'javascript:false';
        div.appendChild(iframe);
        form.action = location.toString();
        form.method = 'POST';
        form.target = "_parent";
        div.appendChild(form);
        form.submit();
    }
    else {            

         if (location.search.indexOf('https://') > 0)
            top.location.href = location.search.replace('?url=https://','http://');
         else if (location.search.indexOf('http://') > 0)
            top.location.href = location.search.replace('?url=http://','http://');  

    }

},
10); 
</script> 

更新:Chrome控制台中的错误

Uncaught ReferenceError: SwapPriceRange is not defined
3extensions::uncaught_exception_handler:8 Error in event handler for (unknown): TypeError: Cannot read property 'state' of null
at CSRecorder.onQueryStateCompleted (chrome-extension://cplklnmnlbnpmjogncfgfijoopmnlemp/content_scripts/recorder.js:43:13)

移动代码并收到此错误:

extensions::uncaught_exception_handler:8 Error in event handler for (unknown): TypeError: Cannot read property 'state' of null
at CSRecorder.onQueryStateCompleted (chrome-extension://cplklnmnlbnpmjogncfgfijoopmnlemp/content_scripts/recorder.js:43:13)
test1.html:1 Resource interpreted as Image but transferred with MIME type text/html: "http://www.mariaraymer.com/".
extensions::uncaught_exception_handler:8 Error in event handler for (unknown): TypeError: Cannot read property 'state' of null
at CSRecorder.onQueryStateCompleted (chrome-extension://cplklnmnlbnpmjogncfgfijoopmnlemp/content_scripts/recorder.js:43:13)

这是远程.js代码:

//***************THE FOLLOWING FUNCTIONS ARE USED THROUGHOUT************
function openWin(url,windowName,options){
var WindowHandle=window.open(url,windowName,options);
WindowHandle.focus();
}

function openWinFormSubmit(frm,frmaction,url,windowName,options){
frm.submit();
var WindowHandle = window.open(url,windowName,options);
document.location = frmaction;
WindowHandle.focus();
}

var ns6=document.getElementById&&!document.all
var ie=document.all

function showSpan(spanID,thetext){
    if (ie) eval("document.all."+spanID).innerHTML=thetext
    else if (ns6) document.getElementById(spanID).innerHTML=thetext
}
function hideSpan(spanID){
    if (ie) eval("document.all."+spanID).innerHTML=' '
    else if (ns6) document.getElementById(spanID).innerHTML=' '
}

function getElementBy(elemTag){
var elem = document.getElementById (elemTag);
if (elem)
    return elem;
var elems = document.getElementsByName (elemTag);
if (elems.length > 0)
    return elems[0];
return null;
}

function toggleOpenCloseElem(elemName){
    var elem = getElementBy (elemName);
    if (!elem)
        return;
    if (elem.style.display == "")
        elem.style.display = "none";
    else
        elem.style.display = "";
}

function toggleOpenElem(elemName){
    var elem = getElementBy (elemName);
    if (!elem)
        return;
    else
        elem.style.display = "";
}

function toggleCloseElem(elemName){
    var elem = getElementBy (elemName);
    if (!elem)
        return;
    else
        elem.style.display = "none";
}

function GetCookie(name) { // use: GetCookie("name");
    var thecookie = document.cookie;
    var index = thecookie.indexOf(name + "=");
    if (index == -1) return null;
    index = thecookie.indexOf("=", index) + 1; // first character
var endstr = thecookie.indexOf(";", index);
if (endstr == -1) endstr = thecookie.length; // last character
return unescape(thecookie.substring(index, endstr));
}

function SetCookie(name, value) { // use: SetCookie("name", value);
 document.cookie=name + "=" + escape(value) + ";";
}

function testForObject(Id){
    var o = document.getElementById(Id);
if (o){return true;}return false;
}

function setAdminSection(str){
    if(str.length >= 14){
    document.getElementById('AdminSection').style.fontSize = '28px' 
}else{
    document.getElementById('AdminSection').style.fontSize = '36px'
}
document.getElementById('AdminSection').innerHTML=str;
}

//***************THE ABOVE FUNCTION IS USED THROUGHOUT************



//***************THE FOLLOWING FUNCTION IS USED FOR FORM        VALIDATION************
function confirmPrompt(msg,url){
    if(confirm(msg)) 
    document.location = url;
}

function confirmPromptFormSubmit(msg,frm,url){
    if(confirm(msg)){
    frm.submit();
    document.location = url;
    }
}

function validateLength(objTB,maxChar){
    if (objTB.value.length > maxChar){return false;}
return true;
}

function validateEmail(objTB){
    var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i; 
    return objRegExp.test(objTB.value);
}

function validateEmailNonReq(objTB){
    var invalidChars = "*|,\":<> []{}`\';()&$#%";
if (objTB.value.length > 0){
    if (objTB.value.indexOf('@') < 0 || objTB.value.indexOf('.') < 0 ||         objTB.value.length < 5){return false;}
    for (var i = 0; i < objTB.value.length; i++){
       if (invalidChars.indexOf(objTB.value.charAt(i)) != -1){return false;}
    }
    return true;
}
return true;
} 

function validateTextBox(objTB){
if (objTB.value==''){return false;}
return true;
}

function validateSelectList(objTB){
    if (objTB.selectedIndex==''){return false;}
return true;
}

function validateNumberTextBoxNonReq(objTB){
    if (isNaN(objTB.value)){return false;}
return true;
}

function validateNumberTextBox(objTB){
if (objTB.value=='' || isNaN(objTB.value)){return false;}
return true;
}

function validateZipCodeTextBoxNonReq(objTB){
    reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);    
if (!reZip.test(objTB.value)){return false;}
return true;
}

//***************THE ABOVE FUNCTION IS USED FOR FORM VALIDATION************



//***************THE FOLLOWING FUNCTIONS ARE USED BY THE PROPERTY COMPARE FEATURE************

function commitCompareList(){
    if(GLOBAL_CompareList != '')        {SetCookie("VAR_CompareList",GLOBAL_CompareList);}
    if(GLOBAL_CompareCount != '')   {SetCookie("CompareCount",GLOBAL_CompareCount);}
}       

function sendToCompare(querystring){
    if (GLOBAL_CompareCount < 2){
    alert('Please check more than 1 listing!');
}else{
    if (GLOBAL_CompareCount > 4){
        alert('Please check no more than 4 listings!');
    }else{
        window.location = "/property/propertycompare.asp?   VAR_CompareList=" + GLOBAL_CompareList + "&CompareCount=" +     GLOBAL_CompareCount + querystring;
    }
}
}

function compareClear(){
    GLOBAL_CompareList = '';
GLOBAL_CompareCount = '';
if(GetCookie('VAR_CompareList') != null && GetCookie('VAR_CompareList') != ""){SetCookie("VAR_CompareList",'');}
if(GetCookie('CompareCount') != null && GetCookie('CompareCount') != ""){SetCookie("CompareCount",'');}
}

function addCompare(obj){
    //the maximum number of listings a user can check to compare
var Max_Number_Properties = 4;

if(obj.checked == true){
    if(GLOBAL_CompareCount == Max_Number_Properties){           
        obj.checked = false;
        alert('You have already chosen ' + Max_Number_Properties + ' properties!');
    }else{
        GLOBAL_CompareList = GLOBAL_CompareList + obj.value;
        GLOBAL_CompareCount = Math.round(GLOBAL_CompareCount) + 1;
    }
}else{
    GLOBAL_CompareCount = Math.round(GLOBAL_CompareCount) - 1;
    GLOBAL_CompareList = GLOBAL_CompareList.replace(obj.value,"");
}
}
    //***************THE ABOVE FUNCTIONS ARE USED BY THE COMPARE TOOL************



//***************THE FOLLOWING FUNCTIONS ARE USED BY THE eNavigator FEATURE************

//Clears eNavigator Cookies
function eNavigatorClear(){
    if(GetCookie('eNavigator_SearchForm_State') != null && GetCookie('eNavigator_SearchForm_State') != ""){SetCookie('eNavigator_SearchForm_State','')};
if(GetCookie('eNavigator_Prev_CenterLat') != null && GetCookie('eNavigator_Prev_CenterLat') != ""){SetCookie('eNavigator_Prev_CenterLat','')};
if(GetCookie('eNavigator_Prev_CenterLng') != null && GetCookie('eNavigator_Prev_CenterLng') != ""){SetCookie('eNavigator_Prev_CenterLng','')};
if(GetCookie('eNavigator_Prev_ZoomLevel') != null && GetCookie('eNavigator_Prev_ZoomLevel') != ""){SetCookie('eNavigator_Prev_ZoomLevel','')};
if(GetCookie('eNavigator_Prev_MapStyle') != null && GetCookie('eNavigator_Prev_MapStyle') != ""){SetCookie('eNavigator_Prev_MapStyle','')};
if(GetCookie('eNavigator_VAR_City') != null && GetCookie('eNavigator_VAR_City') != ""){SetCookie('eNavigator_VAR_City','')};
if(GetCookie('eNavigator_VAR_ZipCode') != null && GetCookie('eNavigator_VAR_ZipCode') != ""){SetCookie('eNavigator_VAR_ZipCode','')};
if(GetCookie('eNavigator_PRM_PropertyTypeCode') != null && GetCookie('eNavigator_PRM_PropertyTypeCode') != ""){SetCookie('eNavigator_PRM_PropertyTypeCode','')};
if(GetCookie('eNavigator_PRM_Minimum_Price') != null && GetCookie('eNavigator_PRM_Minimum_Price') != ""){SetCookie('eNavigator_PRM_Minimum_Price','')};
if(GetCookie('eNavigator_PRM_Maximum_Price') != null && GetCookie('eNavigator_PRM_Maximum_Price') != ""){SetCookie('eNavigator_PRM_Maximum_Price','')};
if(GetCookie('eNavigator_PRM_Minimum_Beds') != null && GetCookie('eNavigator_PRM_Minimum_Beds') != ""){SetCookie('eNavigator_PRM_Minimum_Beds','')}; //KILLS BATHS TOO (don't ask)
}
//***************THE ABOVE FUNCTIONS ARE USED BY eNavigator************

这是实际页面上带有

形式的.js
<script type="text/javascript">
    function validateForm1(frm) {

        var msg = '';

        if (!validateTextBox(frm.VAR_MLSNumber)) { msg = msg + 'One or More MLS Numbers\n'; }

        if (msg == '') {
            return true;
        }
        else {
            msg = 'The following field(s) are required:\n\n' + msg + '\n';
            alert(msg);
            return false;
        }

    }

    function validateForm2(frm) {

        var msg = '';
        var CityCnt = 0;
        var ZipCnt = 0;

        for (var x = 0; x < frm.VAR_City.length; x++) {
            if (frm.VAR_City.options[x].selected) {
                CityCnt = CityCnt + 1;
            }
        }

        for (var x = 0; x < frm.VAR_ZipCode.length; x++) {
            if (frm.VAR_ZipCode.options[x].selected) {
                ZipCnt = ZipCnt + 1;
            }
        }

        if (CityCnt > 10) { msg = msg + '10 or less Cities\n'; }
        if (ZipCnt > 10) { msg = msg + '10 or less Zip Codes\n'; }

        if (frm.VAR_City.selectedIndex < 0 && frm.VAR_ZipCode.selectedIndex < 0) { msg = msg + 'One or more Cities OR Zip Codes\n'; }

        if (msg == '') {
            toggleOpenCloseElem('searchingTR1');
            return true;
        } else {
            msg = 'The following field(s) are required:\n\n' + msg + '\n';
            alert(msg);
            return false;
        }
    }

    function disableFields(selVal) {

        if (selVal == 'COM' || selVal == 'CML' || selVal == 'LND' || selVal == 'IMF' || selVal == 'RSL') {
            if (testForObject('PRM_Minimum_Beds')) {
                frmMain2.PRM_Minimum_Beds.selectedIndex = -1;
                frmMain2.PRM_Minimum_Beds.disabled = true;
            }
            if (testForObject('PRM_Minimum_baths')) {
                frmMain2.PRM_Minimum_baths.selectedIndex = -1;
                frmMain2.PRM_Minimum_baths.disabled = true;
            }
        } else {
            if (testForObject('PRM_Minimum_Beds')) {
                if (frmMain2.PRM_Minimum_Beds.selectedIndex < 0) {
                    frmMain2.PRM_Minimum_Beds.selectedIndex = 0;
                }
                frmMain2.PRM_Minimum_Beds.disabled = false;
            }
            if (testForObject('PRM_Minimum_baths')) {
                if (frmMain2.PRM_Minimum_baths.selectedIndex < 0) {
                    frmMain2.PRM_Minimum_baths.selectedIndex = 0;
                }
                frmMain2.PRM_Minimum_baths.disabled = false;
            }
        }

        if (testForObject('PRM_Custom9')) {
            if (selVal != 'IMF' && selVal != 'RNT') {
                frmMain2.PRM_Custom9.selectedIndex = -1;
                frmMain2.PRM_Custom9.disabled = true;
            } else {
                frmMain2.PRM_Custom9.selectedIndex = 0;
                frmMain2.PRM_Custom9.disabled = false;
            }
        }

        if (testForObject('PRM_Custom12')) {
            if (selVal == 'COM' || selVal == '') {
                frmMain2.PRM_Custom12.disabled = false;
            } else {
                frmMain2.PRM_Custom12.checked = false;
                frmMain2.PRM_Custom12.disabled = true;
            }
        }

    }
</script>

这是表格

<table cellpadding=0 cellspacing=0 border=0 class="tableBorder" width=230px>
  <tr>

</tr>
<tr>
    <td valign=top colspan=0 style="padding:0px; background-color:#FFFFFF;">

        <table border=0 cellpadding=0 cellspacing=0 width=67%>
        <tr>




                <!--td style="border-bottom: solid 1px #000000;"><img src="/images/spacer.gif" width=2></td>
                <td class=searchTab align=center><div onClick="document.location.href='http://mlssearch.topproduceridx.com/property/map.asp';">Map</div></td-->


        </tr>
        <tr>
            <td colspan=0  bgcolor="ffffff">



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


            <form method="get" action="http://mlssearch.topproduceridx.com/property/proplist.asp" name="frmMain2" target="_blank" onSubmit="return(validateForm2(this));">

                <input type="hidden" name="VAR_ShowResultOptions" value="1">            

            <input type="hidden" name="VAR_SearchSource" value="propsearch">

                    <tr>
            <td class="searchPageSectionHeader">Listing Location <font color=FF0000>*</font></td>
        </tr>
        <tr>
        <td valign=top align=left class="searchPageSectionBG" style="padding-top:8px" nowrap>MLS Number:</td>
</tr>
       <tr>
                    <td><input name="VAR_MLSNumber" size=30 maxlength=38 value=""></td></tr>

          <tr class="searchPageSectionBG">

                    <td nowrap style="padding-top:8px" >Street Address:       </td>
                    </tr>
<tr class="searchPageSectionBG">
                    <td width=100%>

                        <input name="PRM_Address" size=30 maxlength=32 value=""><br>

                    </td>

                </tr>

        <tr>
            <td>
                <table border=0 cellpadding=2 cellspacing=2 class="Website_Text">

                </table>
            </td>
        </tr>

            <tr>
                <td class="searchPageSectionHeader">Listing Features</td>
            </tr>

        <tr>
            <td>

                <table border=0 cellpadding=2 cellspacing=0 class="Website_Text" width=80%>



                    <tr class="searchPageSectionBG">
                        <td>&nbsp;Type:</td>
                        <td colspan=0 width=15px>
                            <select name="PRM_PropertyTypeCode" onChange="javascript:disableFields(this.value); SwapPriceRange(this.value);" class="searchPageSectionBG">
                            <option value="">Any listing type</option>

                                    <option value="RES">Single Family Home</option>

                                    <option value="CND">Townhome or Condo</option>

                                    <option value="IMF">Multi-Family Home</option>

                                    <option value="LND">Lots and Land</option>

                                    <option value="COM">Commercial</option>

                                    <option value="FRM">Farm</option>



                            </select>
                        </td>
                    </tr>





                    <tr class="searchPageSectionBG">

                    </tr>




                    <tr class="searchPageSectionBG">
                        <td nowrap>&nbsp;Price:</td>
                        <td align="left">
                            <select name="PRM_Minimum_Price" id="PRM_Minimum_Price" class="searchPageSectionBG">
<option value="">Any price</option>
<option value="50000">$50,000</option>
<option value="100000">$100,000</option>
<option value="150000">$150,000</option>
<option value="200000">$200,000</option>
<option value="250000">$250,000</option>
<option value="300000">$300,000</option>
<option value="350000">$350,000</option>
<option value="400000">$400,000</option>
<option value="450000">$450,000</option>
<option value="500000">$500,000</option>
<option value="550000">$550,000</option>
<option value="600000">$600,000</option>
<option value="650000">$650,000</option>
<option value="700000">$700,000</option>
<option value="750000">$750,000</option>
<option value="800000">$800,000</option>
<option value="850000">$850,000</option>
<option value="900000">$900,000</option>
<option value="950000">$950,000</option>
<option value="1000000">$1,000,000</option>
<option value="1250000">$1,250,000</option>
<option value="1500000">$1,500,000</option>
<option value="1750000">$1,750,000</option>
<option value="2000000">$2,000,000</option>
<option value="">Any price</option>
                            </select></td></tr>
                            <tr class="searchPageSectionBG"><td align="center">
                            to</td>

                            <td align="left">
                            <select name="PRM_Maximum_Price" id="PRM_Maximum_Price" class="searchPageSectionBG">
<option value="">Any price</option>
<option value="50000">$50,000</option>
<option value="100000">$100,000</option>
<option value="150000">$150,000</option>
<option value="200000">$200,000</option>
<option value="250000">$250,000</option>
<option value="300000">$300,000</option>
<option value="350000">$350,000</option>
<option value="400000">$400,000</option>
<option value="450000">$450,000</option>
<option value="500000">$500,000</option>
<option value="550000">$550,000</option>
<option value="600000">$600,000</option>
<option value="650000">$650,000</option>
<option value="700000">$700,000</option>
<option value="750000">$750,000</option>
<option value="800000">$800,000</option>
<option value="850000">$850,000</option>
<option value="900000">$900,000</option>
<option value="950000">$950,000</option>
<option value="1000000">$1,000,000</option>
<option value="1250000">$1,250,000</option>
<option value="1500000">$1,500,000</option>
<option value="1750000">$1,750,000</option>
<option value="2000000">$2,000,000</option>
<option value="">Any price</option>
                            </select>
                        </td>                       
                    </tr>




                <tr class="searchPageSectionBG">



                        <td nowrap>&nbsp;Bedrooms:</td>
                        <td align="left" >
                            <select name="PRM_Minimum_Beds" id="PRM_Minimum_Beds" class="searchPageSectionBG">
                            <option value="" >Any number</option>
                            <option value="1">At least 1</option>
                            <option value="2">At least 2</option>
                            <option value="3">At least 3</option>
                            <option value="4">At least 4</option>
                            </select>&nbsp;
                        </td>


                        </tr>
                        <tr class="searchPageSectionBG">
                        <td nowrap>&nbsp;Bathrooms:</td>
                        <td align="left">
                            <select name="PRM_Minimum_baths" id="PRM_Minimum_baths" class="searchPageSectionBG">
                            <option value="" >Any number</option>
                            <option value="1">At least 1</option>
                            <option value="2">At least 2</option>
                            <option value="3">At least 3</option>
                            <option value="4">At least 4</option>
                            </select>&nbsp;
                        </td>



                </tr>



                </table>

            </td>

        <tr>
            <td>

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



                </table>

            </td>
        </tr>

            <tr>
                <td class="searchPageSectionHeader">Lot Features</td>
            </tr>

        <tr>
            <td>

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



                    <tr class="searchPageSectionBG">
                        <td nowrap>&nbsp;Lot Size (Acres):</td>
                        <td width=100%  color="#7b8283">&nbsp;
                            <select name="VAR_SqFt" class="searchPageSectionBG">

                        <option value="">Any size</option>
                            <option value="0-.49">Less than 0.5</option>
                            <option value=".5-1">0.5 - 1</option>
                            <option value="1-2">1 - 2</option>
                            <option value="2-5">2 - 5</option>
                            <option value="5-10">5 - 10</option>
                            <option value="10.1-1000000">More than 10</option>
                            </select>
                        </td>
                    </tr>





                    <tr class="searchPageSectionBG">
                        <td colspan=0 nowrap>

                            <table border=0 cellpadding=0 cellspacing=0 class="Website_Text">
                            <tr>

                                <td class="searchPageSectionBG"><input type=checkbox value=1 name="PRM_Waterfront" > Waterfront&nbsp;&nbsp;&nbsp;&nbsp;</td>

                            </tr>
                            </table>

                        </td>
                    </tr>


                </table>
            </td>
        </tr>

        <tr>
            <td>



            </td>
        </tr>
        <tr>

                </table>
            </td>
        </tr>
        </table>    

    </td>
</tr>




            <tr>
                <td colspan=0 valign=middle  nowrap align=left >
                    <input type="submit" align="left" value="Search" style="background-color: #ec894d; color: #ffffff; border-color: #ec894d; vertical-align: middle; text-align: center;" class="button">
                <input type=radio name=PRM_OrderBy style="display:none;" value="pReciprocity ASC, pPrice DESC" Checked>                 </td>
            </tr>

            </table>

            <p>

    </td>
</tr>

</form>


</table>

1 个答案:

答案 0 :(得分:0)

您的HTML无效。作为<form>的孩子,您不能<table> <table>的孩子必须是<thead><tbody><tfoot>等表格元素},或<tr>。当您提供这样的无效HTML时,浏览器会尝试修复它,不同的浏览器会以不同的方式执行此操作。发生的事情是提交按钮没有正确连接到表单,因此它没有发送到action网址。

不要将表单放在表格中,而是将表格放在表格中:

<form method="get" action="http://mlssearch.topproduceridx.com/property/proplist.asp" name="frmMain2" target="_blank" onSubmit="return(validateForm2(this));">
    <input type="hidden" name="VAR_ShowResultOptions" value="1">            
    <input type="hidden" name="VAR_SearchSource" value="propsearch">
    <table border=0 cellpadding=0 cellspacing=2 class="Website_Text" width=100%>
    ...
    </table>
</form>

此外,您的<table></table>代码未正确匹配:您有8 <table>和9 </table>