0

I am interacting with a webpage that I need to have java scripting alternatively disabled and then enabled.

I can't change the scripting setting in the browser to disable scripting since some of the website requires scripting be enable to work properly.

The program I am using allows me to execute a javascript but I can't figure out how to code a script that load a page with javascript disabled.

Any ideas how I can run a javascript to disable scripts on the page?

Thanks for all the feedback - A little more background might help.

I am using a program to create a bot that automates some of my repetitive tasks. The problem is that my program doesn't recognize the links generated by java scripting on the first two pages of the process so I have to have scripting disabled in my browser. Unfortunately on the last and final page of the process scripting is required to render a menu.

I am have request with their development team to change this final page so its viewable without scripts but in the meantime I've still got this problem.

I believe I'll be able to make this work by opening a new browser window, executing the window onload script for the first two steps then going back to a regular window for the final step. I'll let you know if it works.

And yes this is for a personal project and the site owners are aware of my attempts to automate their pages with my software.

2
  • 2
    why do you need to disable scripts? You realize that if you disable scripting via scripting (which i'm pretty sure isn't possible) you won't be able to continue your own script... and will thus be stuck. Commented Apr 27, 2011 at 19:44
  • Your own pages? Or any arbitrary page? Commented Apr 27, 2011 at 19:55

4 Answers 4

1

You can't disable scripts using javascript.

Disabling javascript is something that is done within the browser configuration.

If your script is run outside the browser, you may be able to point it at 2 different browsers, one that has javascript enabled and one that doesn't.

Alternatively, some browsers (Firefox) have the notion of "Profiles" that you can start directly - so you could have one profile with javascript enabled and one without it.

Sign up to request clarification or add additional context in comments.

Comments

1

The only way you could force a reload without Javascript is via a meta-refresh in the page's <head> block:

<meta http-equiv="refresh" content="600;url=http://address.to.your/page" />

or output some text to tell people to "click here to refresh".

Basically you're asking "how can I drive my car somewhere after I remove the engine".

Comments

0

You could look into an add-on for your browser that disables scripts.

Particularly one that can disable them on only a few pages per website, and not the whole site.

Comments

0

...with great difficulty!

However, if you can put this right at the top of the document (preferably inside an if statement acting upon whatever trigger you're using to enable/disable JavaScript):

<script>
window.onload = function()
{
    var contents = document.getElementsByTagName('XMP')[0].innerHTML;
    contents = contents.replace(/<script/gi, '<xscript');
    contents = contents.replace(/<\/script/gi, '</xscript');
    contents = contents.replace(/ on([a-z]+=)/gi, ' *$1');
    document.open();
    document.write(contents);
    document.close();
}
document.write("<xmp>");
</script>

That just might do the job. Except for JavaScript running in IFRAMES and things like that. And except for the unlikely scenario that you're actually using the lesser-spotted XMP element somewhere within your pages.

Not working in Safari. Is this just for your own personal use?

6 Comments

Safari requires the <xmp> element's closing tag, so if you can serve that too (right at the bottom of the page), then it will work in Safari too. But if you can control what you're serving, then you might as well include the scripts conditionally on the server.
OK, even better: Use XmlHttpRequest (AKA AJAX, but synchronous) to fetch the source of the current page. Search/Replace away the JavaScript like in my example (could be better, I think you may be able to replace(/<script(.|\n)*?</script>/, '') for example, instead of renaming the script tags, and perhaps prefix the on*= events with &#32; instead of * just in case they accidentally match visible content. Then write that to the document like in my example. All that can be done in the onclick event handler of a button or link. No XMP required. And no need to be right at the top of the document.
... could also do with a regex to remove javascript: URIs.
Thanks, I think this might do what I need it to do. Testing now and will let you know
@greyholme: An afterthought, depending on the variety of the content you're serving, it may also be an idea to remove noscript opening and closing tags so that the noscript element's contents are exposed.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.