简体   繁体   中英

Opera stops loading my page after jquery is loaded

I've looked and looked, but I cannot seem to find a similar situation to mine. I'm using javascript to open a new window and then post information from said window. My problem is that I am trying to load jquery and then load a script for validation that I wrote after it, but Opera seems to stop rendering anything after jquery is loaded. I will post my code, so maybe someone can catch what I missed.

a.document.open("text/html");
a.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />' +        '<link href="css/theme-simple.min.css" rel="stylesheet" type="text/css" />' +
    '<link href="css/animate.min.css" rel="stylesheet" type="text/css" />' +
    '<link rel="stylesheet" type="text/css" href="css/style.min.css" />' +
    '<link rel="stylesheet" type="text/css" href="css/body.min.css" />' +
    '<link rel="icon" type="image/png" href="img/favicon.ico"><style>li {font-size:10pt}</style></head><body><span style="display:none">');
var output = document.getElementById('productbox').innerHTML;
//output = output.replace((/\<IMG /,  "\<ignore"));
output = output.replace(new RegExp("<img ", "gi"), '<ignore');
// bodyText.replace(new RegExp("<font>", "gi"), '');
a.document.write(output.replace(/Total/, "Total per server").replace(/Email/, "").replace(/Print/, "").replace(/Qty:/, "").replace(/<img /, "<ignore"));
//a.document.write(output.replace(/Total/, "Total per server").replace(/Email/, "").replace(/Print/, "").replace(/Qty:/, "").replace(/<img src="\/images\/spinning_the_envelope.gif">/, "").replace(/<img src="\/images\/print30px.gif" width="20px">/, ""));

a.document.write('</span><form id="form2" name="form2" method="POST" action="success.php"><input type="hidden" name="formType" value="quote"><input type="hidden" name="fn" value="contact"><input type="hidden" Name="From" value="Quote from Orange Computers"><input type="hidden" name="Phone" value="314-921-9700"><input type="hidden" name="TollFree" value="877-921-9700"><input type="hidden" name="WebSite" value="www.orangecomputers.com"><br />' +
'<table class="topRow" style="width:500px;"><tr><td><div style="float:left;line-height:25px;">Email Address:</div> <div class="valignTop"><span id="anonemail" class="ei"><input type="text" id="HK" name="Email" size="40" style="height:18px;" /></span> <input id="submitAQuote" type="submit" class="btn valignTop" value="Send This Quote" name="button"></div><div style="clear:left;float:left;display:none;color:red;font-weight:bold;" id="Invalid"></td></tr><tr><td>Comments: optional<br /><textarea style="float:left;width:500px;" rows="5" name="Message" cols="60"></textarea></td></tr><tr><td><textarea rows="25" cols="60" name="Quote" style="float:left;width:500px;height:400px;margin:auto;margin-bottom:2px;cursor:default;" readonly>');
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
curr_month = curr_month + 1;
var curr_hour = d.getHours();
var curr_min = d.getMinutes();
var curr_sec = d.getSeconds();
var millis = d.getMilliseconds();
var random = Math.floor((Math.random() * 100) + 1);
var quoteNumber = String(curr_date) + String(curr_month) + String(curr_hour) + String(random * 3) + String(curr_min) + String(curr_sec) + String(millis);

a.document.write("Please Note: Prices are subject to change without notice. \n");
a.document.write("Quote number: " + quoteNumber + "\n");
a.document.write("Total Per Server: $");
var price = document.getElementById('product-pric').innerHTML;
a.document.write(price);
a.document.write('\n');
var product = document.getElementById('product-title').innerHTML;
a.document.write(product);
a.document.write('\n');
a.document.write('\n');
//var elems = document.forms.myform.elements;
var count = $("#output li" ).length;

for (var i = 0; i <= count; i++) {
    if (a.document.getElementById('pt' + [i]) !== null) {
        var component = document.getElementById('pt' + [i]).innerHTML;
        /*
                    a.document.write(component);
                    */
        component = component.replace(/&(lt|gt);/g, function (strMatch, p1) {
                return (p1 === "lt") ? "<" : ">";
            });
        var strTagStrippedText = component.replace(/<\/?[^>]+(>|$)/g, "");
        a.document.write(strTagStrippedText);
        a.document.write('\n');
        a.document.write('\n');
    }
    else {}
}
a.document.write("Shipping Not Included");
a.document.write('\n');
/*if (a.document.getElementById('Ground2') !== null) {
    var Ground = document.getElementById('Ground2').innerHTML;
    a.document.write(Ground);
    a.document.write('\n');
}
else {}

if (a.document.getElementById('Second Day Air2') !== null) {
    var SDA = document.getElementById('Second Day Air2').innerHTML;
    a.document.write(SDA);
    a.document.write('\n');
}
else {}

if (a.document.getElementById('Next Day Air2') !== null) {
    var NDA = document.getElementById('Next Day Air2').innerHTML;
    a.document.write(NDA);
}
else {} */


a.document.write('</textarea></tr></td>');
a.document.write("<input type='hidden' name='link' value='http://www.orangecomputers.com/node/index.php?command=getQuote&quoteNum=" + quoteNumber + "' />");
var j = 0;
// var elems = document.forms.myform.elements;

for (var i = 0; i <= count; i++) {

    if (a.document.getElementById('pt' + [i]) !== null) {
        var id = document.getElementById('put' + [i]).value;
        if (document.getElementById('putt' + [i]) !== null) {
            var elemDesc = document.getElementById('putt' + [i]).value;
        }
        if (document.getElementById('putt' + [i]) !== null) {
            var elemPrice = document.getElementById('pri' + [i]).value;
        }
        var name = document.getElementById('put' + [i]).name;
        if (name == 'hddId') {
            a.document.write("<input type='hidden' name='hdd" + j + "' value='" + id + "' />");

            var hdDesc = document.getElementById('hdName' + [i]).value;
            a.document.write("<input type='hidden' name='hddName" + j + "' value='" + hdDesc + "' />");

            var hddQty = document.getElementById('qt' + [i]).value;
            a.document.write("<input type='hidden' name='hddQty" + j + "' value='" + hddQty + "' />");

            var hddId = document.getElementById('hddId' + [i]).value;
            a.document.write("<input type='hidden' name='hdRef" + j + "' value='" + hddId + "' />");

            var hddPrice = document.getElementById('pri' + [i]).value;
            a.document.write("<input type='hidden' name='hddPrice" + j + "' value='" + hddPrice + "' />");
        }
        else if (name == 'cpu') {
            a.document.write("<input type='hidden' name='cpu" + j + "' value='" + id + "' />");
        }
        else {
            a.document.write("<input type='hidden' name='elem" + j + "' value='" + id + "' />");
            if (elemDesc !== undefined) {
                a.document.write("<input type='hidden' name='elemName" + j + "' value='" + elemDesc + "' />");
            }
            if (elemPrice !== undefined) {
                a.document.write("<input type='hidden' name='elemPrice" + j + "' value='" + elemPrice + "' />");
            }
        }


        a.document.write('\n');
        a.document.write('&#10;');
        j++;
    }
    else {}
}

var builder = a.document.getElementById('config').value;
var serverQty = a.document.getElementById('qty').value;
var curPrice = a.document.getElementById('product-pric').innerHTML;

a.document.write("<input type='hidden' name='curPrice' value='" + curPrice + "' />");
a.document.write("<input type='hidden' name='serverQty' value='" + serverQty + "' />");
a.document.write("<input type='hidden' name='builder' value='" + builder + "' />");
a.document.write("<input type='hidden' name='quoteNumber' value='" + quoteNumber + "' />");


a.document.write('<tr><td align="right"><input type="submit" class="btn" value="Send This Quote" name="button"></td></tr></table></form>');
a.document.write('<script type="text/javascript" src="scripts/jquery.js"></script>');
a.document.write('<script type="text/javascript" src="scripts/validator.js"></script>');
a.document.write('</body></html>');
//a.document.close();
if (navigator.appName !== "Microsoft Internet Explorer"){ a.document.close()};

Opera loads everything up until jquery and then nothing after it. I've moved the script tag to several different locations to test it, and it's always the same. Nothing after jquery is loaded. Opera doesn't throw an error, and I don't understand what is happening. Any help would be appreciated! Thank you!

step 1: rewrite this. You're not supposed to use document.write , it's a remnant of ancient times and has two very simple modes of operation.

  1. Is DOM still loading? document.write appends data.
  2. Is DOM done loading? ALL document.write CALLS RESET YOUR DOCUMENT TO THE NEW STRING DATA

Never, ever, use document.write . I have no idea what your a variable is, but anything you're adding in there, you can add in there by properly using document.implementation.createDocument , document.createElement , and the standard appendChild , etc. DOM functions

step 2: profit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM