473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

document.write alternatives

21
I have a Javascript code which is in a .js file, I'm aware that document.write doesn't work with XHTML/Firefox however does in I.E

Is there an alternative that does work?
Dec 31 '07 #1
8 3486
dmjpro
2,476 2GB
I have a Javascript code which is in a .js file, I'm aware that document.write doesn't work with XHTML/Firefox however does in I.E

Is there an alternative that does work?
Paste your code here.

Debasis Jana
Dec 31 '07 #2
acoder
16,027 Expert Mod 8TB
I have a Javascript code which is in a .js file, I'm aware that document.write doesn't work with XHTML/Firefox however does in I.E

Is there an alternative that does work?
Do you mean an alternative for XHTML? document.write does work in normal HTML in probably all browsers.
Dec 31 '07 #3
Marks
21
How about another way for it to work with XHTML? =)
Jan 2 '08 #4
acoder
16,027 Expert Mod 8TB
Use the DOM methods, e.g. document.createElement() and set the element's attributes using setAttribute, for example.
Jan 3 '08 #5
Marks
21
Use the DOM methods, e.g. document.createElement() and set the element's attributes using setAttribute, for example.
Here's my code how would I go about changing it?

Expand|Select|Wrap|Line Numbers
  1. rnd.today=new Date();
  2. rnd.seed=rnd.today.getTime();
  3.  
  4. function rnd() {
  5.         rnd.seed = (rnd.seed*9301+49297) % 233280;
  6.         return rnd.seed/(233280.0);
  7. };
  8.  
  9. function rand(number) {
  10.     var result = Math.ceil(rnd()*number);
  11.     if (!result)result++;
  12.         return result
  13. };
  14. var ad_cnt2 = 3;
  15. var ad2 = rand(ad_cnt2);
  16. var link2;
  17. var adBanner2;
  18. var width2
  19. var height2
  20. if (ad2==1) {
  21. link2="http://www.domain.com";
  22. adBanner2="http://www.link2.com/banner.gif";
  23. width2="468";
  24. height2="60";
  25. alt2="Title";
  26. }
  27. document.write('<a href="' + link2 + '" target="_blank">');
  28. document.write('<img class="banner" src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 alt="' + alt2 + '"></a>');
Jan 14 '08 #6
kunal pawar
297 100+
There is alternative way for document.write is assign output to DIV tag
like
document.getElementById("your div id").innerHTML = "your text";
Jan 15 '08 #7
acoder
16,027 Expert Mod 8TB
Here's my code how would I go about changing it?

Expand|Select|Wrap|Line Numbers
  1. ...
  2. document.write('<a href="' + link2 + '" target="_blank">');
  3. document.write('<img class="banner" src="' + adBanner2 + '" width=' + width2 + ' height=' + height2 + ' border=0 alt="' + alt2 + '"></a>');
Create the element and then set its attributes:
Expand|Select|Wrap|Line Numbers
  1. elem = document.createElement("a");
  2. elem.href = link2;
  3. elem.target = "_blank";
  4. document.body.appendChild(elem);
and likewise for the second statement.
Jan 15 '08 #8
acoder
16,027 Expert Mod 8TB
There is alternative way for document.write is assign output to DIV tag
like
document.getElementById("your div id").innerHTML = "your text";
I don't think innerHTML is supported properly yet for XHTML in all browsers.
Jan 15 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
8
by: Jean Pierre Daviau | last post by:
for (var i=0; i< document.images.lenght; i++){ totalWidth = totalWidth + document.images.width; totalHeight = totalHeight + document.images.height; } -- X trême newbe ....... masm32 windows...
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Fredrik | last post by:
How to I solve the following requirement on my application? On a generated aspx page, there should be a button "Create Document". When the user clicks this button, the application creates (on...
31
by: Manfred Kooistra | last post by:
If I have a document like this: <html> <head> <script language=javascript> window.location.href='file.php'; </script> </head> <body> body content
13
by: Gretsch | last post by:
Re XML, Javascript, IE, Firefox Hi, I have a very simple & small XML file (only 7 variables). The code works for IE, but not for Firefox. I've search around and found lots of alternatives, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.