/    Sign up×
Community /Pin to ProfileBookmark

document.write problem

Hi Everyone,

Long story short: im trying to save javascript code to a variable

[CODE]testVar = “<SCRIPT>alert(‘test’);</SCRIPT>”; [/CODE]

and pass it to another webpage who executes it with

[CODE]document.write(testVar);[/CODE]

Now this works great (it comes up with the alert ‘test’) BUT because the document.write was executed supposively AFTER the onload event of <BODY>, it REPLACES the original webpage with the new code I just sent it (which causes all kinds of bad things!).

Anyone got an idea how I can get a webpage to execute javascript commands I send it WITHOUT replacing the original webpage with the code i send it??

Cheers,
Dave.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@toicontienSep 22.2006 — Use the eval() function instead. And without seeing the full HTML and JS involved here, there's not a whole lot more we can do. There are several ways to go about this, depending on how you set up the page.
Copy linkTweet thisAlerts:
@biscuitsauthorSep 22.2006 — Just what I was after, Thanks! ?

Cheers,

Dave.
Copy linkTweet thisAlerts:
@nemesis_256Sep 22.2006 — Your document.write has to be within the body tag, wherever you want it to show up. It obviously has to be within the script tag as well. Is this what you're doing?
Copy linkTweet thisAlerts:
@biscuitsauthorSep 22.2006 — Your document.write has to be within the body tag, wherever you want it to show up. It obviously has to be within the script tag as well. Is this what you're doing?[/QUOTE]

I did try that - and got the same result as before (it kept replacing the page with the text/script i feed document.write) ...

I suppose I could figure out what I was doing wrong before with document.write, but the eval command (I hadnt used the eval function before now) works perfectly for what im trying to do ...

Thanks,

Dave
×

Success!

Help @biscuits spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...