Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript: URL not working in IE6

Status
Not open for further replies.

birdman5

Programmer
Dec 9, 2002
15
0
0
GB
Hi,

I have a small bit of code for reformatting a web page generated from another application. It basically re-builds a table, and applies a stylesheet to the new page.

Embedded in the page, it works fine, but i need it to run as a URL, within the address bar. In IE5, there was no problem with this - any ideas??

The code is (prefixed by javascript:)

Code:
var i=0;
var j=1;
var cap=window.document.title;
var txt="<html><head><link rel=stylesheet href=H:/stylesheet.css></head><body><img src=H:/logo.bmp>"
+cap+
"<br><br><table cellspacing=0 cellpadding=3 border=1>";
mybody=document.getElementsByTagName("body").item(0);
mytable=mybody.getElementsByTagName("table").item(0);
txt=txt+"<tr>";
mytablebody=mytable.childNodes.item(0);
myrow=mytablebody.childNodes.item(0);
while (i<myrow.getElementsByTagName("th").length)
{mycel=myrow.getElementsByTagName("th").item(i);
myceltext=mycel.childNodes.item(0);
txt=txt+"<th>"+myceltext.data+"</th>";
i++;
}
txt=txt+"</tr>";
while(j<mytablebody.getElementsByTagName("tr").length)
{myrow=mytablebody.childNodes.item(j);
txt=txt+"<tr align=right>";
i=0;
while (i<myrow.getElementsByTagName("td").length)
{mycel=myrow.getElementsByTagName("td").item(i);
myceltext=mycel.childNodes.item(0);
txt=txt+"<td>"
+myceltext.data+"</td>";
i++;}
txt=txt+"</tr>";
j++;}
txt=txt+"</table></body></html>";
document.open();
document.write(txt);
document.close();

Regards
Paul
 

Maybe IE6 has a limit on the length of code that can be pasted into the address bar?

I've never seen this amount of code pasted as a URL before - and I'm not sure how "supported" it is, and should be, by browsers.

Have you tried searching MSDN?

Dan
 
IE6 indeed has a limit on the number of characters. ~500 Seems to be the max...

Paul
 
Found a solution to the problem. Instead of 'looping' through the table and rebuilding it that way, i now use the body.InnerHTML object and replace certain values. This saves a lot of space:

Code:
javascript:var cap=window.document.title;var txt="<html><head><link rel=stylesheet href=H:/stylesheet.css></head><body><img src=H:/logo.bmp>"+cap.slice(cap.indexOf("\\",3)+1,cap.indexOf("."))+"<br><br>"+document.body.innerHTML.replace("TABLE ","TABLE cellpadding=0 cellspacing=0 ")+"</body></html>";document.open();document.write(txt);document.close();

This can now be saved as a favourite (a bookmarklet) and run when required.

Paul
 
this would probably work better:

javascript:void(document.body.contentEditable=(document.body.contentEditable=="true"%20?%20false%20:%20true))

__________________________________________________________
"The only difference between me and a mad man is that I'm not mad."
- Dali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top