Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload page without <script> tags

I need to render a page without executing it's JavaScript (however inject my own script), showing the user how the page would look from a bot's POV.

So far I have thought of loading the page using ajax, removing all <script></script> tags from the loaded data, injecting my own <script></script> tags and replacing page html with the filtered data.

Are there any better ways of achieving this?

like image 320
Rob Fox Avatar asked Oct 03 '22 12:10

Rob Fox


2 Answers

Maybe not a better way, but an alternative to using javascript to do what you want:

You can write a (php) server-side script, use file_get_contents() to get the original page contents, use php to remove and replace javascript page contents (str_replace, substr_replace, preg_match) then call this php script in an iframe.

See my related answer for more detail: https://stackoverflow.com/a/17262334/888177

like image 135
Stefan Avatar answered Oct 07 '22 18:10

Stefan


<meta http-equiv="refresh" content="5; url=http://example.com/">

Meta refresh.

EDIT:

So, here's something you can do:

Check out this jquery plugin called fancybox.

What it does is, load remote url content into a neat popup div on the page. You can check if you can modify it's code to make it work how you want.

Also quick headsup: bots don't have cookies as well. So, stripping just script tags won't do. Also have to disable cookies in the request.

like image 34
Prasanth Avatar answered Oct 07 '22 20:10

Prasanth