Solved

Auto Stop Loading Script ?

Posted on 2006-07-01
3
349 Views
Last Modified: 2010-04-06
I need a script that if user reached it ( without clicking or pressing ), it will stop loading the page.
Is it avaiable ? Can you explain for me ?
0
Comment
Question by:vmyth
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 250 total points
ID: 17025533
>>without clicking or pressing
If you want to prevent user from typing in http://url/myscrip.js, then I doubt it's possible (you can obfuscate the code to stop the casual observer though)
But if you want to prevent user from accessing an HTML page that has your javascript code embedded in it, try this:

Use a form with onclick events for buttons & links. When form is submitted, form field data gets inserted into the url. e.g. "http://www.google.com/search?q=javascript"
So if user just types in the base url, your script can check the url & so will know that the page was not reached using a particular button or link.

Won't stop them from typing in the url with the proper input after the '?', but it makes it less convenient for them. But you can set a value that MUST exist in the url, e.g. a really long complex value that no user would want to type out, and set it as a hidden element in the form. That value gets appended to the url when form is submitted via a click.

E.g. run the following example, and look at the url in the address bar after you click

<html>
<!-- Submit via link and submit button - Demo,
      by Ravinder Singh ('wiz' @ the quickmacros forum), 2006-07-01

      Select, copy,paste into notepad, save as c:\temp\google.htm
      Then type that path into address bar in your browser -->

<form name="magic" target=_self method="GET" action="http://www.google.ca/search">
<input type=submit name="sendme" value="Google.ca">
<input type=text name=q size=31 maxlength=2048 value="key" title="Search">
</form>
<a href="#" onclick="document.magic.action='http://www.google.com/search';document.magic.submit();"><B>Search Google.com</B></a>
</html>
0
 
LVL 30

Expert Comment

by:callrs
ID: 17162685
Any update?
0
 

Author Comment

by:vmyth
ID: 17162763
I'm sorry I forgot to click the "Accept" button :D
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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)

743 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

11 Experts available now in Live!

Get 1:1 Help Now