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 cookie detection IE works, Chrome does not work?

Status
Not open for further replies.

norwood451

Technical User
Apr 19, 2007
9
US
Hi – I was excited to find this great code to solve a problem with users blocking cookies. I added it to a iframe page on my site. In IE7 it works great. It detects if the user has cookies enabled, and if not, within the iframe,, it tells the user what the problem is and how to fix it. If cookies are enabled, it works seamlessly in IE. However, when I tested the page in Safari, and Google Chrome the error page is in the iframe no matter what. Does anyone know why it would work in IE and not Chrome and if so, can you tell me how to rewrite the code to work in both browsers? See code-
Please note: I am entering this code in a Office Live web site, so I am limited to where I can put code. It this case it is added to a “html window / ifram within the page ” , with is the only place html code can be entered with an office web site. Currently, the code is not entered into my web page because it does not work with other browsers, but I can set up a test page, if I need to demonstrate the problem. I have temporally add a link to the page to tell users that cookies need to be enabled –kind of a funky solution.
This is the code I found that I added to my iframe Page – the location can be any page, but the norwood.com page is the one that I am using.

<script type="text/javascript">
if (!document.cookie) {
document.location = "}
</script>

This is how it looks in the html page- (all of the code used) – and works with IE.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Arroyo Grande homes & land for sale multiple MLS listings David Norwood central coast real estate California</title>
</head>
<script type="text/javascript">
if (!document.cookie) {
document.location = "}
</script>
<iframe src=" width="843" height="5025"></iframe>
<body>
</body>
</html>
 
Hi

Normally that should not work in any browser. You are asking there "if (no cookie exists)" and so far there is no reason to be any cookie. So is correct to always get the message about no cookies.

First you should set a cookie, only then test to see if is indeed set.

Feherke.
 
Hi Feherke- thank you for your response. Unfortunately, I do not understand your reply, as I am not an expert. I just experiment with code I find. Usually the code I find works and I use it. In this case it did work in IE, so why not in Chrome? I have been looking for a long time and experimenting with ap code, but the code I have found does not work. The result tends to be the code is on the top of the ifram.

Do you have any code that will work for what I am doing?

Thanx again,
 
Hi

norwood451 said:
In this case it did work in IE, so why not in Chrome?
We will need to see that page live to debug it.

In meantime I can only repeat that what you posted so far should not work in any browser. It may seem to work in Explorer if a cookie was set earlier by another page of that site. If you will visit that certain page in Chrome first, then the cookie test will seem to work in Chrome too.

Have you tried what I suggested ?
Feherke said:
First you should set a cookie, only then test to see if is indeed set.
This means to set a cookie before the test :
JavaScript:
[highlight]document[teal].[/teal]cookie[teal]=[/teal][green][i]'foo=bar'[/i][/green][/highlight]
[b]if[/b] [teal](![/teal]document[teal].[/teal]cookie[teal])[/teal] [teal]{[/teal]
   window[teal].[/teal]location[teal].[/teal]href [teal]=[/teal] [green][i]"[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL][/i][/green]
[teal]}[/teal]

Feherke.
 
Hi Feherke- Thanx again for the response. Very much appreciated. YOUR CODE WORKS perfectly…… The results are below.

Per your suggestion, I created a test page called using the problem code.

<script type="text/javascript">
if (!document.cookie) {
document.location = "}
</script>

To see the problem I am WAS having, look at the page with cookies enabled and then refresh the page with cookies disabled. It works perfectly in IE7. Exactly what I want it to do, which is it opens a different page telling the user how to fix the problem when cookies are disable, and when cookies are enable, it works seamlessly showing the content of the page. The only thing that would be better is if the code reconfigures the users computer to except cookies without the user doing anything. : )

Next, if you open the link a Safari browser, you will see that the error or how to page is always present with cookies enabled or disabled. Please note: I plan on creating additional instructions to enable cookie Safari.

To see the SOLUTION to the problem using your code, I created a 2nd test page and called it - I replaced my code with your code below.

<script type="text/javascript">
document.cookie='foo=bar'
if (!document.cookie) {
window.location.href = "}
</script>

WOW! AMAZING! It works in IE7, Safari. It also works with Chrome, which can not be configured to turn off cookies.

Unless you have another or better solution to solve my problem, THANK YOU again. David
 
Hi

David said:
Unless you have another or better solution
Another solution ? You could check the [tt]navigator.cookieEnabled[/tt] property. Theoretically is supported by all major browsers. No idea. I never researched on it.

Better solution ? If better means "reconfigures the users computer to except cookies", fortunately that is not possible.

Note that you are testing the cookies only on page load, but the user can disable it after that. In which case your theory can fail.


Feherke.
 
Would you mind giving me the full code for this code to insert into my test page, I would be guessing on what to do with it otherwise. Is it a script? Do I add it to the existing code you wrote? Sorry for not being as knowegable as I would like to be. I am learning though.

navigator.cookieEnabled

As for the code / testing on load, I was planning on adding the code to each page that has the issue, which I am not sure why I have. I think it has something to do with having the MLS page within the iframe instead of oppening a page seperately. David
 
Hi

You mean you want code example of using [tt]navigator.cookieEnabled[/tt] ? I guess my explanation was abit obscure. The only thing to change is the [tt]if[/tt] condition :
JavaScript:
[b]if[/b] [teal](![/teal][highlight]navigator[teal].[/teal]cookieEnabled[/highlight][teal])[/teal] [teal]{[/teal]
  window[teal].[/teal]location[teal].[/teal]href [teal]=[/teal] [green][i]"[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL][/i][/green]
[teal]}[/teal]
The advantage is that you not need to set a dummy cookie before testing it.

The disadvantage is that I am not sure it really works in all browsers.


Feherke.
 
Tried navigator.cookieEnabled - and works with all but Opera, as it gives a blank iframe page in Opera. However, also if (!document.cookie)does not work with Opera, in that it does not open up the error page (fix problem page) and when cookies are off shows as an error in the iframe. Do you know anyone using Opera anyway? Do you think I should worry about Opera?
 
Hi feherke - below are the 2 test sites- if Opera works for you, do you know why it does not work for me. It does not go to the test page (?), which was my problem from the staart with IE- I proball should fix the problem with Opera also, as I agree with wanting everything correct. Thanx again.

Both codes do not work the same as IE in Opera.

has the: if (!navigator.cookieEnabled)
Code:
<script type="text/javascript">
document.cookie='foo=bar'
if (!document.cookie) {
   window.location.href = "[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL]
}
</script>

AND
[URL unfurl="true"]http://dnorwood.com/cookie_test.aspx[/URL] has the: if (!document.cookie)[code]

<script type="text/javascript">
document.cookie='foo=bar'
if (!navigator.cookieEnabled) {
   window.location.href = "[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL]
}
</script>
 
Hi

Well, your pages are not working neither here. But I am sure the problem is not with the cookie testing JavaScript code.

Sorry, but I hate obfuscated JavaScript and [tt]iframe[/tt]s inside [tt]iframe[/tt]s. I have no time for debugging such self-ball-kicking.

Feherke.
 
Feherke - what I wanted when I stated to fix this problem was not to have the error page open in the iframe. I wanted a separate page to open up that described how to fix the cookie error problem, which is “Object reference not set to an instance of an object”. However, I could not find any code that would do that and could only find the code in the original message that opened the page in the same iframe that solved the problem, but did not work correctly in all browsers.

Based on your last message, I’m guessing that what the problem with Opera is having an iframe in an iframe. I did not know the code I was using is obfuscated.

If you think it would fix the Opera problem, could you provide non obfuscated code that would open a go to fix it page that is not in the iframe page, but its own web page?

Thank you so much for taking the time to communicate all the information you have provided. It is very much appreciated and I always look forward to hearing from you.
David
 
Hi

David said:
I'm guessing that what the problem with Opera is having an iframe in an iframe.
I would not say that. [tt]iframe[/tt] inside [tt]iframe[/tt] is technically correct and browsers have nothing against it. But it is conceptually wrong and hard to debug when [tt]iframe[/tt] contents are manipulated with JavaScript.
David said:
I did not know the code I was using is obfuscated.
Well, let us make a small trip :
[ul]
[li]open in a browser[/li]
[li]open the View Source window[/li]
[li]search for "cookieEnabled" in the source code[/li]
[li]you will find it in this piece of JavaScript code :
Code:
[small]setTimeout([highlight]'HtmlControlJS.loadFrame\x28
\x27ctl00_IWS_WH_CPH_Content_HtmlControl1\x27, \x27\x5cx3c\x5cx21DOCTYPE 
html PUBLIC \x5cx22-\x5cx2f\x5cx2fW3C\x5cx2f\x5cx2fDTD XHTML 1.0 
Transitional\x5cx2f\x5cx2fEN\x5cx22 \x5cx22http\x5cx3a\x5cx2f
\x5cx2f[URL unfurl="true"]www.w3.org\x5cx2fTR\x5cx2fxhtml1\x5cx2fDTD\x5cx2fxhtml1-[/URL]
transitional.dtd\x5cx22\x5cx3e\x5cx0d\x5cx0a\x5cx3chtml xmlns\x5cx3d
\x5cx22http\x5cx3a\x5cx2f\x5cx2f[URL unfurl="true"]www.w3.org\x5cx2f1999\x5cx2fxhtml\x5cx22[/URL]
\x5cx3e\x5cx0d\x5cx0a\x5cx3chead\x5cx3e\x5cx0d\x5cx0a\x5cx3cmeta 
http-equiv\x5cx3d\x5cx22Content-Type\x5cx22 content\x5cx3d\x5cx22text
\x5cx2fhtml\x5cx3b charset\x5cx3dutf-8\x5cx22 \x5cx2f\x5cx3e\x5cx0d\x5cx0a
\x5cx3ctitle\x5cx3eArroyo Grande homes \x5cx26 land for sale multiple MLS 
listings David Norwood central coast real estate California\x5cx3c
\x5cx2ftitle\x5cx3e\x5cx0d\x5cx0a\x5cx3c\x5cx2fhead\x5cx3e\x5cx0d\x5cx0a
\x5cx3cscript type\x5cx3d\x5cx22text\x5cx2fjavascript\x5cx22\x5cx3e\x5cx0d
\x5cx0aif \x5cx28\x5cx21navigator.cookieEnabled\x5cx29 \x5cx7b\x5cx0d
\x5cx0a   document.location \x5cx3d \x5cx22http\x5cx3a\x5cx2f
\x5cx2fdnorwood.com\x5cx2fNo_Cookies_Enabled.aspx\x5cx22\x5cx0d\x5cx0a
\x5cx7d\x5cx0d\x5cx0a\x5cx3c\x5cx2fscript\x5cx3e\x5cx0d\x5cx0a
\x5cx3ciframe src\x5cx3d\x5cx22http\x5cx3a\x5cx2f
\x5cx2fsearchlax.rapmls.com\x5cx2fClientPortal.aspx
\x5cx3fTJhkRvbuacuchF1EIpHbjYciBR70iW0BLaQkyDkwubiuOlt9UsvKHZN1Yu5eYluwbGWt
L9CJCFirXSubZnmw0Ta5yXBPrlVfwgCMOl6CmYQpxYrVCOR6QVZ8FoRb8rN3ShIU1UorbNedrWn
msvCibGHvKFmhZB80KCEQTiKr\x5cx2fVTRrF2LCaIGEUjjQiOULQPVPMm16JKe7ArgVHiFP5Sv
tXCESfnWx\x5cx2fhrnQt5JDzV4j6VG7Z\x5cx2fPxYiotyZqoETZH\x5cx2bO\x5cx26hidMLS
\x5cx3dCCRM\x5cx26hidEntryPoint\x5cx3dMW1\x5cx26KeyRid\x5cx3d1\x5cx22 
width\x5cx3d\x5cx22843\x5cx22 height\x5cx3d\x5cx225025\x5cx22\x5cx3e\x5cx3c
\x5cx2fiframe\x5cx3e\x5cx0d\x5cx0a\x5cx3cbody\x5cx3e\x5cx0d\x5cx0a\x5cx3c
\x5cx2fbody\x5cx3e\x5cx0d\x5cx0a\x5cx3c\x5cx2fhtml\x5cx3e\x5cx0d\x5cx0a
\x27,1033, \x272.02.2715.0\x27\x29\x3b'[/highlight], 0);[/small]
[/li]

[li]cut out [tt]setTimeout()[/tt]'s first parameter ( highlighted above with yellow )[/li]
[li]use that string as parameter of an [tt]alert()[/tt] call[/li]
[li]the [tt]alert()[/tt] will say this :
Code:
[small]HtmlControlJS.loadFrame('ctl00_IWS_WH_CPH_Content_HtmlControl1', [highlight pink]'\x3c\x21DOCTYPE html PUBLIC \x22-\x2f\x2fW3C\x2f\x2fDTD 
XHTML 1.0 Transitional\x2f\x2fEN\x22 \x22http\x3a\x2f\x2f[URL unfurl="true"]www.w3.org\x2fTR[/URL]
\x2fxhtml1\x2fDTD\x2fxhtml1-transitional.dtd\x22\x3e\x0d\x0a\x3chtml 
xmlns\x3d\x22http\x3a\x2f\x2f[URL unfurl="true"]www.w3.org\x2f1999\x2fxhtml\x22\x3e\x0d\x0a[/URL]
\x3chead\x3e\x0d\x0a\x3cmeta http-equiv\x3d\x22Content-Type\x22 content\x3d
\x22text\x2fhtml\x3b charset\x3dutf-8\x22 \x2f\x3e\x0d\x0a\x3ctitle
\x3eArroyo Grande homes \x26 land for sale multiple MLS listings David 
Norwood central coast real estate California\x3c\x2ftitle\x3e\x0d\x0a\x3c
\x2fhead\x3e\x0d\x0a\x3cscript type\x3d\x22text\x2fjavascript\x22\x3e
\x0d\x0aif \x28\x21navigator.cookieEnabled\x29 \x7b\x0d\x0a   
document.location \x3d \x22http\x3a\x2f\x2fdnorwood.com
\x2fNo_Cookies_Enabled.aspx\x22\x0d\x0a\x7d\x0d\x0a\x3c\x2fscript\x3e\x0d
\x0a\x3ciframe src\x3d\x22http\x3a\x2f\x2fsearchlax.rapmls.com
\x2fClientPortal.aspx
\x3fTJhkRvbuacuchF1EIpHbjYciBR70iW0BLaQkyDkwubiuOlt9UsvKHZN1Yu5eYluwbGWtL9C
JCFirXSubZnmw0Ta5yXBPrlVfwgCMOl6CmYQpxYrVCOR6QVZ8FoRb8rN3ShIU1UorbNedrWnmsv
CibGHvKFmhZB80KCEQTiKr\x2fVTRrF2LCaIGEUjjQiOULQPVPMm16JKe7ArgVHiFP5SvtXCESf
nWx\x2fhrnQt5JDzV4j6VG7Z\x2fPxYiotyZqoETZH\x2bO\x26hidMLS\x3dCCRM
\x26hidEntryPoint\x3dMW1\x26KeyRid\x3d1\x22 width\x3d\x22843\x22 height\x3d
\x225025\x22\x3e\x3c\x2fiframe\x3e\x0d\x0a\x3cbody\x3e\x0d\x0a\x3c\x2fbody
\x3e\x0d\x0a\x3c\x2fhtml\x3e\x0d\x0a'[/highlight],1033, '2.02.2715.0');
[/small]
[/li]

[li]cut out [tt]loadFrame()[/tt]'s second parameter ( highlighted above with pink )[/li]
[li]use that string as parameter of an [tt]alert()[/tt] call[/li]
[li]the [tt]alert()[/tt] will say this :
Code:
[small]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Arroyo Grande homes & land for sale multiple MLS listings David Norwood central coast real estate California</title>

</head>

<script type="text/javascript">

if (!navigator.cookieEnabled) {

   document.location = "[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL]

}

</script>

<iframe src="[URL unfurl="true"]http://searchlax.rapmls.com[/URL]
/ClientPortal.aspx?TJhkRvbuacuchF1EIpHbjYciBR70iW0BLaQkyDkwubiuOlt9UsvKHZN1
Yu5eYluwbGWtL9CJCFirXSubZnmw0Ta5yXBPrlVfwgCMOl6CmYQpxYrVCOR6QVZ8FoRb8rN3ShI
U1UorbNedrWnmsvCibGHvKFmhZB80KCEQTiKr/VTRrF2LCaIGEUjjQiOULQPVPMm16JKe7ArgVH
iFP5SvtXCESfnWx/hrnQt5JDzV4j6VG7Z/PxYiotyZqoETZH+O&hidMLS=CCRM&
hidEntryPoint=MW1&KeyRid=1" width="843" height="5025"></iframe>

<body>

</body>

</html>[/small]
[/li]
[/ul]
And finally we got some clear code. That looks correct enough to be functional. ( Ignoring the fact that the [tt]script[/tt] and [tt]iframe[/tt] tags are between the [tt]head[/tt] and [tt]body[/tt] sections, in the middle of nothing. )

But let us take a look at what happens with that code. It was passed as the second parameter to the HtmlControlJS.loadFrame() method, which looks like this :
Code:
[small]    loadFrame[teal]:[/teal] [b]function[/b][teal]([/teal]id[teal],[/teal] content[teal],[/teal] 
lcid[teal],[/teal] build[teal])[/teal]
    [teal]{[/teal]
        [b]if[/b] [teal](![/teal] HtmlControlJS[teal].[/teal]loadedFrames[teal][[/teal]id[teal]])[/teal]   [gray]// If it has already been loaded, then don't reload it.[/gray]
        [teal]{[/teal]
            [b]if[/b] [teal]([/teal]content [teal]==[/teal] [b]null[/b][teal])[/teal]
            [teal]{[/teal]
                content [teal]=[/teal] HtmlControlJS[teal].[/teal]content[teal][[/teal]id[teal]];[/teal]
            [teal]}[/teal]
            [b]else[/b]
            [teal]{[/teal]
                HtmlControlJS[teal].[/teal]content[teal][[/teal]id[teal]][/teal] [teal]=[/teal] content[teal];[/teal]
            [teal]}[/teal]

            [b]try[/b]
            [teal]{[/teal]
                [b]var[/b] iframe [teal]=[/teal] window[teal].[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal]id[teal]);[/teal]
                [b]if[/b] [teal](([/teal]iframe[teal].[/teal]style[teal].[/teal]height [teal]==[/teal] [green][i]'0px'[/i][/green][teal])[/teal] [teal]||[/teal] [teal]([/teal]iframe[teal].[/teal]style[teal].[/teal]height [teal]==[/teal] [green][i]'[/i][/green][teal])[/teal] [teal]||[/teal] [teal]([/teal]iframe[teal].[/teal]style[teal].[/teal]height [teal]==[/teal] [green][i]'auto'[/i][/green][teal]))[/teal]
                [teal]{[/teal]
                    HtmlControlJS[teal].[/teal]resizeFrames[teal][[/teal]id[teal]][/teal] [teal]=[/teal] [b]true[/b][teal];[/teal]
                [teal]}[/teal]
                
                [b]var[/b] iframeDoc [teal]=[/teal] [teal]([/teal]iframe[teal].[/teal]contentWindow [teal]||[/teal] iframe[teal].[/teal]contentDocument[teal]);[/teal]
                [b]if[/b] [teal]([/teal]iframeDoc[teal].[/teal]document[teal])[/teal] iframeDoc [teal]=[/teal] iframeDoc[teal].[/teal]document[teal];[/teal] [gray]// if we have a window ref get a doc ref[/gray]
                    
                HtmlControlJS[teal].[/teal][COLOR=
darkgoldenrod]writeDocument[/color][teal]([/teal]iframeDoc[teal],[/teal] 
content[teal],[/teal] lcid[teal],[/teal] build[teal]);[/teal]
                [COLOR=darkgoldenrod]setTimeout[/color][teal]([/teal][green][i]"HtmlControlJS.resizeFrame('"[/i][/green][teal]+[/teal]id[teal]+[/teal][green][i]"');"[/i][/green][teal],[/teal] [purple]0[/purple][teal]);[/teal]  [gray]// delay reizeFrame() call to give FireFox a chance to load the dom.[/gray]
            [teal]}[/teal]
            [b]catch[/b][teal]([/teal]LoadException[teal])[/teal]            
            [teal]{[/teal]
                [COLOR=darkgoldenrod]setTimeout[/color][teal]([/teal][green][i]"HtmlControlJS.loadFrame('"[/i][/green][teal]+[/teal]id[teal]+[/teal][green][i]"', null, "[/i][/green][teal]+[/teal]lcid[teal]+[/teal][green][i]", '"[/i][/green][teal]+[/teal]build[teal]+[/teal][green][i]"');"[/i][/green][teal],[/teal] [purple]5[/purple][teal]);[/teal]
                [b]return[/b][teal];[/teal]
            [teal]}[/teal]
            
            HtmlControlJS[teal].[/teal]loadedFrames[teal][[/teal]id[teal]][/teal] [teal]=[/teal] [b]true[/b][teal];[/teal]
            HtmlControlJS[teal].[/teal]content[teal][[/teal]id[teal]][/teal] [teal]=[/teal] [b]null[/b][teal];[/teal]

            [gray]// Capture the window onResize event if this is the 
first HTML control loaded.[/gray]
            [gray]//[/gray]
            [b]var[/b] size [teal]=[/teal] [purple]0[/purple][teal];[/teal]
            [b]for[/b][teal]([/teal][b]var[/b] x [b]in[/b] 
HtmlControlJS[teal].[/teal]loadedFrames[teal])[/teal]
            [teal]{[/teal]
                size[teal]++;[/teal]
            [teal]}[/teal]
            [b]if[/b] [teal]([/teal]size [teal]==[/teal] [purple]1[/purple][teal])[/teal]
            [teal]{[/teal]
                HtmlControlJS[teal].[/teal]oldOnResize [teal]=[/teal] 
window[teal].[/teal]onresize[teal];[/teal]
                window[teal].[/teal]onresize [teal]=[/teal] 
HtmlControlJS[teal].[/teal]onResize[teal];[/teal]
            [teal]}[/teal]
        [teal]}[/teal]
    [teal]}[/teal][teal],[/teal][/small]
So it is passed forward as the second parameter to
HtmlControlJS.writeDocument(), which looks like this :
Code:
[small]    writeDocument[teal]:[/teal] [b]function[/b][teal]([/teal]doc[teal],[/teal] content[teal],[/teal] 
lcid[teal],[/teal] build[teal])[/teal]
    [teal]{[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]open[/color][teal]();[/teal]
        
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'[/URL][/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">'[/URL][/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<head>'[/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<title>none</title>'[/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<link type="text/css" rel="stylesheet" href="/_layouts/'[/i][/green] [teal]+[/teal] lcid [teal]+[/teal] [green][i]'/wh/stylesV2
/masterroot.css?b='[/i][/green][teal]+[/teal] build [teal]+[/teal][green][i]'" />'[/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<link type="text/css" rel="stylesheet" href="theme.css" />'[/i][/green][teal]);[/teal] [gray]// This file is not cached, so no 
versioning[/gray]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<base target="_parent" />'[/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'</head>'[/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'<body class="MSC_Body" style="border: 0px none black; margin: 
0px; padding: 0px; background-color: transparent;">'[/i][/green][teal]);[/teal]
        
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal]content[teal]);[/teal]
        
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'</body>'[/i][/green][teal]);[/teal]
        doc[teal].[/teal][COLOR=darkgoldenrod]writeln[/color][teal]([/teal][green][i]'</html>'[/i][/green][teal]);[/teal]
        
        doc[teal].[/teal][COLOR=darkgoldenrod]close[/color][teal]();[/teal]
    [teal]}[/teal][/small]

As you can see, when written out content is placed in the body of a HTML document. But as we saw above, the content already contains an ( almost correct ) HTML document. So the resulted HTML will be anything, but not correct.

If you want the browser to do what you want, you have to give the browser what it expects : valid markup and code.

I hope the above explains why I consider this self-ball-kicking. Honestly, I would dump that code, together with the [tt]iframe[/tt]s. I have no idea how all this looks on the ASP side, but I consider it unmaintainable and would expect that any further modification/debugging will be a pain.

Feherke.
 
Hi Feherke:

Thank you again for taking the time to show me the problems and why. I wish I could take advangtage of your suggestions, but I can not have access all of the sourse code with this web site -MSN office. The only code I have control over is what is listed below. MSN Office builds this overall site, and I can control certain aspects of the site. In this case I need a way to give my clients MLS information. MSN office allows me to create what they call html modules- All of the code I have control over is in the html module listed below. I can not change the source code unless I want to start completly over and build an entire new web site, which I do not have the time to do. Overall the site seems to work fine, but the MLS pages are causing cookie problems with the Default settings in some of the browsers. Firefox and Chrome's defalt setting work fine, but IE7 and safari and opera defalut settings do not work- I bleive the reason is the combination of both sites causing the problem (MSN and where I get the MLS page, as it is compounded using the iframe - I have used redirect pages, but the problem is the same and a very messy site for users. As you can see I have a link telling users that a problems exists when cookies are not enabled, but is a funky solution. I am open to sugestion, but I am limited to what I can do to fix the problem.

As you know, all of the browsers are working with the code below except for Opera and I do not know why Opera is different. The only reason I can think of is that Opera does not like script code in the iframe. So, I thought if there was a code that would open a seperate page, it would solve my problem. Do you know if there is a "go to page" code for what I am trying to do that does not open the error page in the iframe?

Thank you again, I did read your comments, and may be able to use your suggestions in my next new web site, when I have time to build it.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Arroyo Grande homes & land for sale multiple MLS listings David Norwood central coast real estate California</title>
</head>
<body>
<script type="text/javascript">
if (!navigator.cookieEnabled) {
document.location = "}
</script>
<iframe src="Yu5eYluwbGWtL9CJCFirXSubZnmw0Ta5yXBPrlVfwgCMOl6CmYQpxYrVCOR6QVZ8FoRb8rN3ShI
U1UorbNedrWnmsvCibGHvKFmhZB80KCEQTiKr/VTRrF2LCaIGEUjjQiOULQPVPMm16JKe7ArgVH
iFP5SvtXCESfnWx/hrnQt5JDzV4j6VG7Z/PxYiotyZqoETZH+O&hidMLS=CCRM&
hidEntryPoint=MW1&KeyRid=1" width="843" height="5025"></iframe>
</body>
</html>
 
Hi

Probably will not help me imagine the circumstances, but anyway, what is MLS ?
David said:
I do not know why Opera is different
Sometimes they take some words strictly. For example once W3C recommended to browser developers to set a default [tt]padding[/tt] of 8px around the [tt]body[/tt]. Every other browser set a [tt]margin[/tt] of 8px. Seems that later W3C adjusted the recommendation to the statistics, so now Opera looks dumb.

Is that whole HTML document you posted above specified by you ? If yes, based on what we saw previously when analyzing HtmlControlJS.writeDocument(), I would cut it down to the [tt]script[/tt] tag, like this :
Code:
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green][b]>[/b]
if (!navigator.cookieEnabled) {
   document.location = "[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL]
}
[b]</script>[/b]
Or if you want to try to opening a new window :
Code:
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green][b]>[/b]
if (!navigator.cookieEnabled) {
   window.open("[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx",'warnwin')[/URL]
}
[b]</script>[/b]
Sorry, I have no idea for improvement. I will try some debugging later with Opera, but I have a feeling that will lead nowhere. :-(

Feherke.
 
Hi

Hmm... In my post at 31 Mar 10 13:15 I used [tt]window.location.href[/tt] instead of [tt]document.location[/tt], but I not insisted on changing it, as it seemed to work.

( Note that [tt]document.location[/tt] was originally read-only and assigning value to it should rise an error. Later was modified to writable as many people skipped reading the documentation and directly jumped to blaming the browser.

Also note that [tt]location[/tt] is and object and setting a string to it should mess up things. However in many browsers this was supported by the very beginning, for the same reason as above. )

Although it seems to work, my latest debugging seems to reveal some problems with this. Please give it a try using [tt]window.location.href[/tt] instead :
Code:
[b]<script[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text/javascript"[/i][/green][b]>[/b]
if (!navigator.cookieEnabled) {
   [highlight]window.location.href[/highlight] = "[URL unfurl="true"]http://dnorwood.com/No_Cookies_Enabled.aspx"[/URL]
}
[b]</script>[/b]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top