Solved

How to stop browser navigation by javascript?

Posted on 2002-06-13
19
791 Views
Last Modified: 2007-12-19
Is there anyway to stop the current ASP page processing with a javascript command?

I would like to simulate the browser's stop button.
But I would like to do it programmatically with javascript or vbscript.



0
Comment
Question by:RobertoTY
  • 6
  • 5
  • 4
  • +3
19 Comments
 
LVL 11

Expert Comment

by:mouatts
ID: 7077110
No it is not possible to stop the execution of the ASP as this is occuring on the server and the javascript is on the client. HTTP provides no mechanism to interupt a request/response transaction.

Having said that if you are happy simply to stop the results of the ASP from being displayed then you can do it simply by selecting a different page. This has the effect of 'closing' the http connection. Whatever the ASP was doing will still occur but you won't see the results (so if it deleting your entire database its still deleted)

eg
document.location='someotherpage.asp';
0
 
LVL 3

Expert Comment

by:davlun20080
ID: 7077420
or if you want to stop the processing on the server, and do something else, either in asp or by sending another file to the browser, you can use response.end and response.redirect respectively.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 7077535
Netscape:
window.stop()

Michel
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7077651
davlun20080: what you say is correct but you can't trigger this to happen from the client once the request has been made.

Equally window.stop will not interrupt the processing on the server.

Steve
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 7077657
But it sure will cut the connection to the browser and the web server should see that and stop the server process

Michel
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7077739
Michel,

You would hope so but it doesn't, well not reliably. For example write an ASP script that loops (as I managed to do yesterday!!!) you can kill the browser and the ASP will continue to process until IIS, I think, flushes its buffer. By which time it is too late. Even with buffering turned off it will continue to process.

And thank god it does. Imagine a muli-part insert/update that got stopped part way through simply because the connection with the user failed. We would be up to our eye balls in corrupt databases if IIS could stop ASP (or a CGI)from processing.

As I recall there was a long running PAQ in the CGI area where someone wanted to interrupt a CGI running under Appache and they found it couldn't be done. They could inhibit the output but this only occurs after the CGI completes.

Steve
0
 

Author Comment

by:RobertoTY
ID: 7078081
mouatts,
I think you didn't understand it clearly. What I do need is something like michel´s suggestion. I just need to simulate the stop button from the browser to cut the connection.

In my ASP page processing I have a loop that tests the "IsClientConnected" property of the response object, to check if the processing should still go on.

I would never write code to make database tasks, trusting on the connection with the client browser.

All I need is a way to cut the connection to the server from within the client, using script. Does IE has a property like that from netscape: window.stop() ?

0
 

Author Comment

by:RobertoTY
ID: 7078088
I want to cut the connection to the server, but I don´t want to loose the content of the current page.

What if i try to navigate the page to another location and use an event that is fired after the connection is closed, but before the navigation, to cancel the navigation?
Is is possible? How?

0
 
LVL 11

Expert Comment

by:mouatts
ID: 7078178
Well you wouldn't be writing code that relies on the connection because as I said it won't get interupted. But any how what you are now asking is slightly different.

I'm not aware, and I have had a look, for any equivilent to window.stop on IE.

The only way I can think that you can really achieve this is with a hidden frame.
Imagine you page with the link or form that triggers the ASP and the link that simulates the stop sitting in FRAMEA. The target for the ASP is the hidden FRAMEB.

When you ASP executes to completion it transmits the javascript to display the resultant page. At the start of of this javascript is a test for a variable within FRAMEA. If it is true then it executes the rest of the javascript which writes the new page to FRAMEA. If false it does nothing.

The 'stop' button in FRAMEA when clicked sets the value of the variable to false, hence stopping the resultant page being displayed.

Steve

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:RobertoTY
ID: 7078243
I thought about the hidden frame. I tried to do it, but the problem is that I would have to send all the data back to the original frame, by using javascript.

And this is extremely slow. I´m going to display, hundreds of lines, and I want them to be shown as they are sent.
The best solution would be the stop simulation.
0
 

Author Comment

by:RobertoTY
ID: 7078272
I thought about the hidden frame. I tried to do it, but the problem is that I would have to send all the data back to the original frame, by using javascript.

And this is extremely slow. I´m going to display, hundreds of lines, and I want them to be shown as they are sent.
The best solution would be the stop simulation.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7078385
I think you mis-understand you are only re-displaying those hundreds of lines if they do NOT hit the stop button.

If they hit the stop button you page is unchanged.

Steve
0
 

Author Comment

by:RobertoTY
ID: 7078402
Is there a way to send the ESC key to the browser. Simulating the user pressing the ESC key to make the browser stop?
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7078433
No.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 7081210
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8285298
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or so. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 8285615
recommendation:PAQ
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8356979
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Accepted Solution

by:
Chmod earned 0 total points
ID: 8404975
As recommended

Chmod
Community Support Moderator @Experts Exchange
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now