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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page hanging 3

Status
Not open for further replies.

topcat1a

Programmer
Jan 6, 2005
34
GB
Hi,

When the following code executes it gets to the end of inProductSearch function and doesn’t return back to the body of the HTML to write ‘5’.

In IE the page finishes and everything up to number 2 is displayed, it does not write '5'. The same in Firefox, however in Firefox the hourglass just stays there. Has anyone got any idea why this is happening.

<html>
<head>
<script LANGUAGE="javascript" TYPE="text/javascript">

function breadcrumb()
{
var currentURL = document.URL
inProductSearch(1, currentURL)
document.write("2")
}

function inProductSearch(callerID,currentURL)
{
if(callerID == 1)
{
var URLArray = currentURL.split("=")
var temp = URLArray.length
var finalString = URLArray[temp - 1]
document.write("finalString is: " + finalString)
document.write("<a href = ' + finalString + ".co.uk'>" + finalString + "</a>")
document.write("1")
}
}
</script>
</head>

<body onload="breadcrumb()">
5
</body>
</html>
 
I've run some test and the page isn't hanging, it works fine, well kind of!

I'm unsure what relationship JS and the browser have, but I've added a whole load of standard HTML in the body tag, but only get what is writen to the browser via the JS.

View the source of what is displayed in the browser, notice anything?

Yup it only contains what the JS wrote and nothing else!

Someone who's an expert here on JS will have to explain, I have no idea why it is behaving this way!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
>function breadcrumb()
>{
> var currentURL = document.URL
> inProductSearch(1, currentURL)
> document.write("2")
[tt] [red]document.close();[/red][/tt]
>}
 
so you have to close the document being written to before the HTML will display.



"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
For this kind of operation, yes, similarly, such as write the entire html script to a popup right from a blank ... from the opener.
 
Looks like we found our expert, thank you tsuji
 
tsuji,

don't forget about opening the document as well.

Code:
function breadcrumb()
{
   var currentURL = document.URL;
   document.open();
   inProductSearch(1, currentURL);
   document.write("2");
   document.close();
}



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I used to have the whole ritual in place as well... There is a big asymmetry of criticality open() vs close(). I just put the most critical part into relief. I must confess I didn't come across one single case where taking out .open() break the script and where introducing it save the script. That's what I mean by asymmetry. But, it is so much more satisfactory having it there. Thanks, cLFlaVa, for the note.
 
Hi the page hanging is all gone however the html is not being displayed, any ideas? I have added document.close() on the end of the breadcrumb() function.
 
you cannot call a document.write line after the page has been rendered. to make your javascript work, try doing something like this:

Code:
<html>
<head>
<script LANGUAGE="javascript" TYPE="text/javascript">

function breadcrumb()
{
   var currentURL = document.URL;
   document.open();
   inProductSearch(1, currentURL);
   document.write("2");
   document.close();
}

function inProductSearch(callerID,currentURL)
{
   if(callerID == 1)
    {
        var URLArray = currentURL.split("=")
        var temp = URLArray.length
        var finalString = URLArray[temp - 1]
        document.write("finalString is: " + finalString)
        document.write("<a href = '[URL unfurl="true"]http://www.asd"[/URL] + finalString + ".co.uk'>" + finalString + "</a>")
        document.write("1")
    }
}
</script>
</head>

<body>

<script type="text/javascript"><!--
breadcrumb();
//--></script>

</body>
</html>



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thank you it works OK now.

One thing though, I have not got the

document.open()

All I did was get rid of the <body onload="breadcrumb()"> and move it into the script tag you have put up.

 
add it, it's one little copy/paste!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top