...

View Full Version : browserName=navigator.appName not working



boemboem
06-16-2009, 05:32 PM
Hello all,

I have this code and I don't understand why this isn't working.

Head section:

<script>
function IEorMoz(){

// get browser resolution
var browserName=navigator.appName;
if (browserName=="Netscape"){

// Netscape/FireFox
document.write('<div class='s6l_short_url_form6' id='uitkomst2'><a href='javascript:document.write('<html><head><title>{$txt_short_url}</title></head>
<body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();'><img src='../template/default/image/slepen.png' alt='Twit This!' width='171' height='44' border='0' align='top'></a></div>');

} else {

// IE
document.write('<div class='s6l_short_url_form6' id='uitkomst2'><a href='javascript:document.write('<html><head><title>{$txt_short_url}</title></head>
<body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();'><img src='../template/default/image/slepen.png' alt='Twit This!' width='171' height='44' border='0' align='top'></a></div>');
}
}
</script>

Body section:

<div onclick='IEorMoz();'>get res</div>

Thanks a ton in advance
ps I know the 2 div's are the same, but this is only for testing.

boemboem
06-16-2009, 06:02 PM
I have also tries this instead of the


<script type = "text/javascript">
function getres(){

// get browser resolution
var browserName=navigator.appName;
if (browserName=="Netscape"){

// Netscape/FireFox
document.write("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.write("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"..\/template\/default\/image\/slepen.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");

} else {

// IE
document.write("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.write("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"..\/template\/default\/image\/slepen.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
}
</script>

tomws
06-16-2009, 07:18 PM
ps I know the 2 div's are the same, but this is only for testing.

Then how do you know it's not working?

Raphael
06-16-2009, 07:36 PM
It would probably work better to store the stuff you're going to write in a var, so do something like this:



var newpage=''
newpage+='lorem ipsum<a href="link.html">lorem ipsum</a>'
newpage+='more text here'
...
document.write(newpage)


I think another issue is escaping characters. If you start and end a javascript string with a single quote and use double quotes (or escaped single quotes) inside it usually is safer.

I see that you're trying to write single quotes inside of other single quotes, and if you do that you have to escape it like this:

document.write('<a href="javascript:myfunction(\'myfirstvar\')">lorem ipsum</a>')

boemboem
06-16-2009, 07:38 PM
I try to convert a excisting div into a document.write("");
Maybe the code before the document.write is not good?

Philip M
06-16-2009, 07:44 PM
document.write statements must be run before the page finishes loading. Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. So document.write is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.

Kor
06-16-2009, 08:32 PM
Detecting browsers by their navigator.appName is not reliable. Browsers do often spoof their name. You should rather detect a certain contested method (and code accordingly).

boemboem
06-16-2009, 10:52 PM
I'm a bit confused now, so I tried something easier, it still doesn't work
Can somebdy tell me how I can mak this work?


<html>
<head>
<script type="text/javascript">
function writeJS(){
var str='';
str+='<a href="javascript:document.write('<html><head><title>{$txt_short_url}</title></head>
<body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();"><img src="..\/template\/default\/image\/slepen.png" width="171" height="44" border="0"><\/a>';
str+='To be or not to be!';
document.write(str);
}

</script>
</head>
<body onLoad="writeJS()";>

If there is an image, it works ok!

</body>
</html>

boemboem
06-17-2009, 11:24 AM
At the moment I got this working


<script type="text/javascript">
function writeJS(){
var browserName=navigator.appName;
if (browserName=="Netscape")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/luxsci.com\/blog\/wp-content\/uploads\/2009\/02\/firefox-logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
else
{
if (browserName=="Microsoft Internet Explorer")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/blogs.nitobi.com\/alexei\/wp-content\/uploads\/2008\/03\/internet_explorer_7_logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
}
</script>

<body onLoad="writeJS()";>

Can somebody tell me how I can push this in a div with GetElementByID??
Some handles are welcome please.

Philip M
06-17-2009, 11:54 AM
[/CODE]

Can somebody tell me how I can push this in a div with GetElementByID??
Some handles are welcome please.

Javascript is case-sensitive.

document.getElementbyId("mydiv").innerHTML = whatever

Perhps it might be an idea to buy an introductory textbook on Javascript.

boemboem
06-17-2009, 12:32 PM
Thank you for your reply. Buying a Javascript book (for Dummy's :D would be a good idea, I will look for that. I can understand that you don't want to create my wishes, but I do my best to understand javascript, when I post a message here, I do that because I got stuck somewhere. With some handles I can try further. :)

Is it possible to put a complete document.write in a document.getElementbyId("mydiv").innerHTML like:


document.getElementbyId("mydiv").innerHTML = document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/luxsci.com\/blog\/wp-content\/uploads\/2009\/02\/firefox-logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");

Philip M
06-17-2009, 12:40 PM
Is it possible to put a complete document.write in a document.getElementbyId("mydiv").innerHTML like:


document.getElementbyId("mydiv").innerHTML = document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/luxsci.com\/blog\/wp-content\/uploads\/2009\/02\/firefox-logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");


No. See post #6.

Why do you want to do these strange things? What are you actually trying to achieve?

boemboem
06-17-2009, 05:11 PM
Hello again,

What I actually want to achieve is pretty simple, but not for me, it gives me headaches :D

I'll try to explain in my best english.

1 - I have a image in a div, with a link in it. The html code for that one is this:


<div class="s6l_short_url_form6">
<a href="javascript:document.write('<html><head><title>Short URL</title></head> <body><form name=\'urlform\' action=\'http://twiturl.nl/\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form>');document.forms[0].submit();"><img src="http://www.survivalbond.nl/images/news/duim.jpg" width="111" height="44" /></a>
</div>

2 - When somebody uses IE or Mozilla FF, a different picture has to be shown in a DIV, the code I have for that is. Wich actually works good.


<script type="text/javascript">
function writeJS(){
var browserName=navigator.appName;
if (browserName=="Netscape")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/luxsci.com\/blog\/wp-content\/uploads\/2009\/02\/firefox-logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
else
{
if (browserName=="Microsoft Internet Explorer")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/blogs.nitobi.com\/alexei\/wp-content\/uploads\/2008\/03\/internet_explorer_7_logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
}
}
</script>

3 - The problem now is that I don't know how to call the function writeJS() in a way that it doesn't overwrite the whole page like you said in #6
I'm out of ideas at the moment.

Basicly in short. I want to have two different div's, containing two different images, the only shows in Internet Explorer, the other only in Mozilla FF

tomws
06-17-2009, 05:26 PM
You're making it more complicated than it needs to be.


<div class="s6l_short_url_form6">
<a href="javascript:document.write('<html><head><title>Short URL</title></head> <body><form name=\'urlform\' action=\'http://twiturl.nl/\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form>');document.forms[0].submit();"><img src="http://www.survivalbond.nl/images/news/duim.jpg" width="111" height="44" /></a>
</div>


Suggestions...

First, you have a document.write as your link. That's going to do exactly what you don't want to happen. So, remove it.

Second, why are you trying to write an entirely new page when the link is clicked? That also not what you say you want to happen. So, remove that.

Point the href to the javascipt function only.

To change the image, either:
1) Give an ID to your div and make your function modify only the innerHTML of that div, or
2) Give an ID to your image tag and make you function modify the .src of that tag.

Don't use document.write* anywhere.

boemboem
06-17-2009, 05:39 PM
Tomws, thank you for your reply.

The code needs to be like this because it's a bookmarklet. This is the original html code. The only difference will be the image shown to a IE user or FF user.


<a href="javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$page_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /><input type=\'hidden\' name=\'title\' value=\''+encodeURIComponent(document.title)+'\' /><input type=\'hidden\' name=\'twitter\' value=\'1\' /></form></body></html>');document.forms[0].submit();" title="{$txt_bookmark_me}" class="s6l_bookmarklet"><img src="../default/image/slepen.png" width="171" height="44" border="0" /></a>

At this point I can't see the forest though the trees :D

tomws
06-17-2009, 06:01 PM
My fail. I thought the image changed when clicked on by a user. I mis-read. In that case, the #2 from above should be sufficient.

2) Give an ID to your image tag and make you function modify the .src of that tag.

As an example, I tossed this little script together to play with changing the image source randomly:

<html>
<head>
<script type="text/javascript">
function changeIt()
{
var imgArr = new Array("/ASUonBlack.jpg","/logo_eapdd_lg.gif","/ualr.gif");
document.getElementById('thatImgId').src=imgArr[Math.floor(Math.random()*3)];
}
</script>
</head>
<body>
<div><img id="thatImgId" src="/ualr.gif"/></div>
<div><a href="javascript:changeIt()">change image</a></div>
</body>


So you can change your image source the same way (see the one javascript line above), give the image tag an ID as above, and then you need to call the image changer function in the body tag with onload(), I think. Like this:


<body onload="myFunctionName();">

boemboem
06-17-2009, 06:25 PM
Hi Tomws, as I see this code of your's it changes the image within a div and that's very nice, but I think it doesn't fit my needs. I also don't see how I could use your code for my needs, but that's my ignorance. In case I wasn't clear enough, I try to write it down as simple as possible.

Basicly a div with a image and link (that very long one), which changes on browser vendor.

The image:

../template/default/image/slepen.png

The link:

javascript:document.write('<html><head><title>{$txt_short_url}</title></head>
<body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();

The code for browser vendor recognision

<script type="text/javascript">
function writeJS(){
var browserName=navigator.appName;
if (browserName=="Netscape")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/luxsci.com\/blog\/wp-content\/uploads\/2009\/02\/firefox-logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
else
{
if (browserName=="Microsoft Internet Explorer")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/blogs.nitobi.com\/alexei\/wp-content\/uploads\/2008\/03\/internet_explorer_7_logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
}
}
</script>

The code above overwrites the whole page as Philip M allready said before.
For a example, please take a look here:

http://vl.am notice the Bookmarklet on top of the page, that one changes on browser vendor.

tomws
06-17-2009, 07:15 PM
Hi Tomws, as I see this code of your's it changes the image within a div and that's very nice, but I think it doesn't fit my needs.

It's not written to fit your needs. It's rather written as an example of how to change the image source with a function call.


I also don't see how I could use your code for my needs, but that's my ignorance.

If you're just wanting to change the image, I'm not sure I can make it any clearer than my last post.

Another example of changing image source: http://snippets.dzone.com/posts/show/4418
If it's not the image after all, see innerHTML: http://www.tizag.com/javascriptT/javascript-innerHTML.php

boemboem
06-18-2009, 08:44 AM
Can you please explain me how I get a long link like that and image in this script?


<script type="text/javascript">
function writeJS(){
var browserName=navigator.appName;
if (browserName=="Netscape")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/luxsci.com\/blog\/wp-content\/uploads\/2009\/02\/firefox-logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
else
{
if (browserName=="Microsoft Internet Explorer")
{
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/blogs.nitobi.com\/alexei\/wp-content\/uploads\/2008\/03\/internet_explorer_7_logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
}
}
</script>

Philip M
06-18-2009, 12:30 PM
It is slightly depressing that you have not taken any notice of the advice in Kor's post #7. If your disregard experienced people's helpful advice, they tend to lose interest in your problem.

Have a look at:-

http://www.javascriptkit.com/javatutors/objdetect.shtml

"Basicly in short. I want to have two different div's, containing two different images, the one only shows in Internet Explorer, the other only in Mozilla FF." (I won't bother to ask what the point of that is.)

Why not use conditional compilation? That detects IE infallibly.

http://www.javascriptkit.com/javatutors/conditionalcompile.shtml

A neat way to test is:-


var IE = /*@cc_on!@*/false;

returns true for IE, false for others.

So,


if (IE) {document.getElementById("theImage").src = "IEpicture.jpg"}
else {document.getElementById("theImage").src = "Firefoxpicture.jpg"}

boemboem
06-18-2009, 02:44 PM
Excuse me for missing expert advice, I must say that I didn't understand what Kor said, and everywhere were I looked for browser determination, navigator.appName came up.

Philip, thank you for your reply, I see it can be done much easier, however I dont understand how I can get that long link on those images.

This is the link, can you give me a example, I will try the rest.


document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$page_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /><input type=\'hidden\' name=\'title\' value=\''+encodeURIComponent(document.title)+'\' /><input type=\'hidden\' name=\'twitter\' value=\'1\' /></form></body></html>');document.forms[0].submit();

Philip M
06-18-2009, 03:08 PM
<script type = "text/javascript">

var IE = /*@cc_on!@*/false; //returns true for IE, false for others.
if (IE) {
document.writeln("<div class=\"s6l_short_url_form6\" id=\"uitkomst2\"><a href=\"javascript:document.write(\'<html><head><title>{$txt_short_url}<\/title><\/head>");
document.writeln("<body><form name=\\'urlform\\' action=\\'{$short_url}\\' method=\\'post\\'><input type=\\'hidden\\' name=\\'u\\' value=\\'\' + window.location.href + \'\\' \/><\/form><\/body><\/html>\');document.forms[0].submit();\"><img src=\"http:\/\/blogs.nitobi.com\/alexei\/wp-content\/uploads\/2008\/03\/internet_explorer_7_logo.png\" alt=\"Twit This!\" width=\"171\" height=\"44\" border=\"0\" align=\"top\"><\/a><\/div>");
}
</script>

I am using IE and I get an image which I click on it redirects me to a page which cannot be displayed.

boemboem
06-18-2009, 08:53 PM
Thank you very much in Phillip. I think I have to give it up. Your sollution works great, but gives me the blanc page with only a image again, instead of a image in a div. Thank you'll for your effort and help. :thumbsup:

Kor
06-18-2009, 08:57 PM
The idea is clear: why do you need to detect the browser? Just tell us in simple words why do you need that. We need to know your basic need.

Only after that we might try to find a solution to your problem. Remember, your main task as a developer is not to detect the browser, but to create a crowssbrowser web document.

boemboem
06-19-2009, 08:05 AM
Hi Kor,

I want to have a image as bookmarklet.

In IE, you have to right click on the image and "save as" favorite or "save as" favorite bar item.
http://www.twiturl.nl/docu/ie.jpg


In FF, you can drag the image to your bookmark bar, that's why people need to see the right image on every browser. When this works I will try to find a sollution for Opera too.
http://www.twiturl.nl/docu/ff.jpg

These pictures need to have the following link, When you hit the bookmarklet on the favoritesbar, the URL of a page will be copy/paste to my site.

This is a example from a other page, the pictures also.


javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$page_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /><input type=\'hidden\' name=\'title\' value=\''+encodeURIComponent(document.title)+'\' /><input type=\'hidden\' name=\'twitter\' value=\'1\' /></form></body></html>');document.forms[0].submit();" title="{$txt_bookmark_me}" class="s6l_bookmarklet"><img src="../default/image/slepen.png" width="171" height="44" border="0" />

This must be placed in a div for positioning. I hope this is the information you can use. Thank you for your time.

Philip M
06-19-2009, 08:11 AM
A kludge solution is to have two web pages, one for IE and one for others (Firefox), and redirect IE accordingly.

var IE = /*@cc_on!@*/false;
if (IE) {window.location = .............}

boemboem
06-19-2009, 10:19 AM
Hi Phillip,

Are there any other options?

Philip M
06-19-2009, 10:47 AM
Hi Phillip,

Are there any other options?

Yes, sure. You could forget Javascript and take up underwater motorcycling instead. :D:D:D

boemboem
06-19-2009, 11:08 AM
Great, I'll keep that in mind :)

tomws
06-19-2009, 05:55 PM
Wouldn't innerHTML work for this?

Using Philip's last code:


var IE = /*@cc_on!@*/false;
if (IE) {
var theDivCode = "<a href=\"javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$page_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /><input type=\'hidden\' name=\'title\' value=\''+encodeURIComponent(document.title)+'\' /><input type=\'hidden\' name=\'twitter\' value=\'1\' /></form></body></html>');document.forms[0].submit();\" title=\"{$txt_bookmark_me}\" class=\"s6l_bookmarklet\"><img src=\"../default/image/slepen.png\" width=\"171\" height=\"44\" border=\"0\" /></a>";
document.getElementById('uitkomst2').innerHTML = theDivCode;
}

Quote-escaping may be incorrect there.

boemboem
06-19-2009, 06:25 PM
That looks good, Can you please check if the quote escapes are right here, I accedently provided the wrong url


var theDivCode = "<a href=\"javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();" title="{$txt_bookmark_me}"><img src=\"../template/default/image/slepen.png\" width=\"171\" height=\"44\" border=\"0\" /></a>";

tomws
06-19-2009, 06:49 PM
var theDivCode = "<a href=\"javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();\" title=\"{$txt_bookmark_me}\"><img src=\"../template/default/image/slepen.png\" width=\"171\" height=\"44\" border=\"0\" /></a>";

I added (and highlighted) three extra escapes.

boemboem
06-19-2009, 07:30 PM
I dont see anything in FireFox


<script type = "text/javascript">
function Teleur() {
var IE = /*@cc_on!@*/false;
if (IE)
{
var theDivCode = "<a href=\"javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();\" title=\"{$txt_bookmark_me}\"><img src=\"../template/default/image/slepen.png\" width=\"171\" height=\"44\" border=\"0\" /></a>";
document.getElementById('Iexmoz').innerHTML = theDivCode;
}
else
{
document.getElementById('Iexmoz').innerHTML = theDivCode;
}
}
</script>


<div class="s6l_short_url_form1" id="Iexmoz"></div>

Please try this URL too in Iexplorer, http://twiturl.nl/index.php and fill in a webadress, after you hit the go button.

You'll see in top a blue image "sleep dit naar jouw favorieten balk", this one works perfect and is hard coded.

The pig picture is generated with the code above in this thread, and that link doesn't work unfortunately.

Any hints ;)

tomws
06-19-2009, 07:39 PM
I dont see anything in FireFox

With that funciton code, you shouldn't see anything in any non-IE browser. You forgot the set the variable to the correct div code in the else statement. Copy the one for IE and paste it with the modifications for use with non-IE browsers.

tomws
06-19-2009, 07:44 PM
Javascript errors in IE:


Line: 43
Error: 'document.newurlform.newurl' is null or not an object

Line: 19
Error: 'document.newurlform.newurl' is null or not an object

tomws
06-19-2009, 07:48 PM
And you have at least two divs with the same ID: uitkomst2

tomws
06-19-2009, 07:52 PM
And you have a case-sensitivity problem. IEXMOZ is not the same as Iexmoz.

boemboem
06-19-2009, 07:52 PM
I thought the var would be enough for both statements. Can you see why the else statement doesnt work and why the Piggie image doesn't have the same effect as the image in top of the page.


<script type = "text/javascript">
function Teleur() {
var IE = /*@cc_on!@*/false;
if (IE)
{
var theDivCode = "<a href=\"javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();\" title=\"{$txt_bookmark_me}\"><img src=\"http://donbosco5.classy.be/Lentequiz/varken2.jpg\" width=\"171\" height=\"44\" border=\"0\" /></a>";
document.getElementById('Iexmoz').innerHTML = theDivCode;
}
else
{
var theDivCode = "<a href=\"javascript:document.write('<html><head><title>{$txt_short_url}</title></head><body><form name=\'urlform\' action=\'{$short_url}\' method=\'post\'><input type=\'hidden\' name=\'u\' value=\'' + window.location.href + '\' /></form></body></html>');document.forms[0].submit();\" title=\"{$txt_bookmark_me}\"><img src=\"http://donbosco5.classy.be/Lentequiz/varken2.jpg\" width=\"171\" height=\"44\" border=\"0\" /></a>";
document.getElementById('Iexmoz').innerHTML = theDivCode;
}
}
</script>

boemboem
06-19-2009, 09:10 PM
I have solved a few problems, this one I can't solve

Line: 19
Error: 'document.newurlform.newurl' is null or not an object


var tex = document.newurlform.newurl.value;

Line: 43
Error: 'document.newurlform.newurl' is null or not an object


var twtTitle = document.newurlform.newurl.value;

When is this possible?

tomws
06-19-2009, 09:16 PM
From what I can see, there is no element with the id newurlform. Perhaps you mean to have it pointed to the entry form (form id="form")?

boemboem
06-19-2009, 10:55 PM
Problem solved with the errors in IE. The only thing now is that IE makes a mess of all the DIV's, FF does a good job, are there any crossbrowser rules for placing div's?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum