Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
192
rated 0 times [  195] [ 3]  / answers: 1 / hits: 96747  / 15 Years ago, fri, april 17, 2009, 12:00:00

Firstly, is there a way to use document.write() inside of JQuery's $(document).ready() method? If there is, please clue me in because that will resolve my issue.


Otherwise, I have someone's code that I'm supposed to make work with mine. The catch is that I am not allowed to alter his code in any way. The part that doesn't work looks something like this:


document.write('<script src="http://myurl.com/page.aspx?id=1"></script>');

The script tag is referencing an aspx page that does a series of tests and then spits out something like so:


document.write('<img src="/image/1.jpg" alt="Second image for id 1">')

The scripts are just examples of what is actually going on. The problem here is that I've got a document.write() in the initial script and a document.write() in the script that get's appended to the first script and I've got to somehow make this work within JQuery's $(document).ready() function, without changing his code.


I have no idea what to do. Help?


More From » jquery

 Answers
3

With the requirements given, no, you can't use document.write without really hosing up the document. If you're really bent on not changing the code, you can override the functionality of document.write() like so and tack on the result later:



var phbRequirement = ;

$(function() {
document.write = function(evil) {
phbRequirement += evil;
}
document.write(Haha, you can't change my code!);
$('body').append(phbRequirement);

});


Make sure you overwrite the document.write function before it is used. You can do it at anytime.



The other answers are boring, this is fun, but very pretty much doing it the wrong way for the sake of fulfilling the requirements given.


[#99688] Monday, April 13, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kieraelsies

Total Points: 718
Total Questions: 103
Total Answers: 104

Location: England
Member since Sun, May 21, 2023
1 Year ago
kieraelsies questions
Tue, Aug 3, 21, 00:00, 3 Years ago
Tue, Feb 23, 21, 00:00, 3 Years ago
Thu, Nov 12, 20, 00:00, 4 Years ago
Wed, Sep 9, 20, 00:00, 4 Years ago
Mon, Sep 16, 19, 00:00, 5 Years ago
;